How can I always set jFrame first and turn focuse on until it is closed?

My program has two different frames, and the second one is open, when I press the jButton button, this is the first frame, so when the second frame opens, I want the second frame to always be on top and focused until it is closed, the user is not allowed to do anything in the first window until the second window is closed. How can i do this?

+5
source share
1 answer
JFrame frame = new JFrame ();
frame.setAlwaysOnTop (true);

If you want the frame to always be focused, you probably have to use a modal dialog instead of a JFrame:

JDialog dialog = new JDialog ();
dialog.setModal (true);
dialog.setAlwaysOnTop (true);
dialog.setModalityType (ModalityType.APPLICATION_MODAL);
+19
source

All Articles