Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JFrame in Java

Tags:

java

swing

jframe

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.

like image 257
Mats_SX Avatar asked May 22 '09 19:05

Mats_SX


1 Answers

You need a JDialog with modal = true. From the Javadocs:

modal - specifies whether dialog blocks user input to other top-level windows when shown.

like image 123
Michael Myers Avatar answered Sep 27 '22 22:09

Michael Myers