Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i set a jFrame to be always on top and focuse enabled until it is closed?

Tags:

java

swing

jframe

There are two different Frames in my program and the second one open when i click the jButton is the first frame,so when the second frame is opened, I want the second frame to be always on top and focused until it is close. user can't be allowed to do anything in the first window until the second window is closed. how can i do this?

like image 710
Nayana Rajapaksha Avatar asked Feb 10 '13 08:02

Nayana Rajapaksha


1 Answers

JFrame frame = new JFrame ();
frame.setAlwaysOnTop (true);

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

JDialog dialog = new JDialog ();
dialog.setModal (true);
dialog.setAlwaysOnTop (true);
dialog.setModalityType (ModalityType.APPLICATION_MODAL);
like image 75
Mikhail Vladimirov Avatar answered Oct 29 '22 03:10

Mikhail Vladimirov