I am using a JFrame as a pop-up from a main frame, where the user is supposed to enter some information and then press OK. But the problem is that once this sub-frame has opened up, I want the program to ignore any other signal until the OK button is pressed, similar as how it is done with JOptionPanes. As it is now, you could click the button to open up the sub-frame several times, thus getting several frames, and this is not the intention (it causes a lot of bugs even).
I could solve it with a boolean that is true once the OK button is pressed, but that doesn't seem like a cool way to fix it. I feel there has to be some other way of doing it, seeing as I can see the sought-after effect coming from my JOptionPanes, but can't get to it.
Cheers.
You need a JDialog
with modal = true
. From the Javadocs:
modal
- specifies whether dialog blocks user input to other top-level windows when shown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With