When two JFrames are enabled, I want the user to be able to use only one in the top (think of that like an error pop up on your screen, when you can't press anything but the popup itself). I am aware of the class JInternalFrame and I chose not to use it for my program. Thanks in advance :)
Asked
Active
Viewed 38 times
0
-
1Possible duplicate of [How to make a JFrame Modal in Swing java](http://stackoverflow.com/questions/1481405/how-to-make-a-jframe-modal-in-swing-java) – user1803551 May 13 '17 at 16:44
-
See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson May 13 '17 at 18:14
2 Answers
2
Use JDialog, you can set your main frame as the JDialog's parent frame, so that whenever your main frame and JDialog will display, you will be able to click only the JDialog, not your main frame.

Deepesh Choudhary
- 660
- 1
- 8
- 17
1
You want a modal behaviour, then. I think you can try using JDialog instead of JFrame, something like:
JDialog dialog = new JDialog(parentFrame, title, true); //parameters: owner, title and modal
dialog.getContentPane().add(somePanel);
dialog.pack();
dialog.setVisible(true);
You can read more about it here: http://docs.oracle.com/javase/tutorial/uiswing/misc/modality.html

doughaase
- 245
- 4
- 13