T_Shah
asked on
JDialog always on top
Hello,
I am using Java 1.4.2_06 with OS windowsXP.
I am working on a software that we can customize. I created a popup button (Test) that open Dialog box.
I created a panel. In that panel I put two other panels. One panel has JTable and other panel has two buttons.
When user click on button (Test) dialog needs to be displayed.
I tried using
JDialog jd = new JDialog(null, "Hello",true);
I put null because I don't how how to get parent frame of that application.
This does not work...
Any other solution??
Thanks
I am using Java 1.4.2_06 with OS windowsXP.
I am working on a software that we can customize. I created a popup button (Test) that open Dialog box.
I created a panel. In that panel I put two other panels. One panel has JTable and other panel has two buttons.
When user click on button (Test) dialog needs to be displayed.
I tried using
JDialog jd = new JDialog(null, "Hello",true);
I put null because I don't how how to get parent frame of that application.
This does not work...
Any other solution??
Thanks
You can use JFrame component (which contains panel and other components you mentioned) instead of null. Is it acceptable?
You said you don't know how to get parent frame for that application.
If you have code for that application, then it is possible to pass parent frame to JDialog constructor.
I suppose that given code is inside your JFrame class, so you can use this instead of null.
If on the other hand given code is inside some other class you will need to pass "this" reference from JFrame class to that class.
If you have code for that application, then it is possible to pass parent frame to JDialog constructor.
I suppose that given code is inside your JFrame class, so you can use this instead of null.
If on the other hand given code is inside some other class you will need to pass "this" reference from JFrame class to that class.
> This does not work...
should do, what exactly is happening?
Are you making the dialog visible using the setVisible() method.
And do you add compoinents to your dialog?
should do, what exactly is happening?
Are you making the dialog visible using the setVisible() method.
And do you add compoinents to your dialog?
ASKER
Well,
Yes, I make dialog visible.
addComponent(pmain,scrollP ane,0,0,0, 1);
JDialog dlg = new JDialog(parent, "Test", true);
dlg.getContentPane().setLa yout(new BorderLayout());
dlg.getContentPane().add(B orderLayou t.CENTER, pmain);
dlg.setDefaultCloseOperati on(JDialog .DISPOSE_O N_CLOSE);
dlg.setSize(800,500);
dlg.setVisible(true);
when I extends my class to JFrame, it does not stay on the top. It flicks through all the application windows that I have open through (outlook, notepad, wordpad, eclipse, etc...) and hide at the back and the software window that I am doing customization comes on the top.
I even tried JOptionPane but does the same thing.
JOptionPane.showMessageDia log(null,p main,"Test ",JOptionP ane.INFORM ATION_MESS AGE);
* I don't know why it goes through all the windows that are open
* and then hide
Thanks
Yes, I make dialog visible.
addComponent(pmain,scrollP
JDialog dlg = new JDialog(parent, "Test", true);
dlg.getContentPane().setLa
dlg.getContentPane().add(B
dlg.setDefaultCloseOperati
dlg.setSize(800,500);
dlg.setVisible(true);
when I extends my class to JFrame, it does not stay on the top. It flicks through all the application windows that I have open through (outlook, notepad, wordpad, eclipse, etc...) and hide at the back and the software window that I am doing customization comes on the top.
I even tried JOptionPane but does the same thing.
JOptionPane.showMessageDia
* I don't know why it goes through all the windows that are open
* and then hide
Thanks
if you want it to stay on top (of a specific frame) then you need to specify that frame as the owner. It will not stay on toip of *all* windows.
Try adding
dlg.setAlwaysOnTop(true);
to the code you gave. You will get:
addComponent(pmain,scrollP ane,0,0,0, 1);
JDialog dlg = new JDialog(parent, "Test", true);
dlg.getContentPane().setLa yout(new BorderLayout());
dlg.getContentPane().add(B orderLayou t.CENTER, pmain);
dlg.setDefaultCloseOperati on(JDialog .DISPOSE_O N_CLOSE);
dlg.setSize(800,500);
dlg.setAlwaysOnTop(true);
dlg.setVisible(true);
dlg.setAlwaysOnTop(true);
to the code you gave. You will get:
addComponent(pmain,scrollP
JDialog dlg = new JDialog(parent, "Test", true);
dlg.getContentPane().setLa
dlg.getContentPane().add(B
dlg.setDefaultCloseOperati
dlg.setSize(800,500);
dlg.setAlwaysOnTop(true);
dlg.setVisible(true);
ASKER
Thnaks for reply.
dlg.setAlwaysOnTop(true);
This method is not available in 1.4.2_06
dlg.setAlwaysOnTop(true);
This method is not available in 1.4.2_06
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.