Link to home
Start Free TrialLog in
Avatar of T_Shah
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
Avatar of UrosVidojevic
UrosVidojevic
Flag of Serbia image

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.
Avatar of Mick Barry
> 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?
Avatar of T_Shah
T_Shah

ASKER

Well,
Yes, I make dialog visible.
addComponent(pmain,scrollPane,0,0,0,1);
JDialog dlg = new JDialog(parent, "Test", true);
dlg.getContentPane().setLayout(new BorderLayout());
dlg.getContentPane().add(BorderLayout.CENTER, pmain);
dlg.setDefaultCloseOperation(JDialog.DISPOSE_ON_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.showMessageDialog(null,pmain,"Test",JOptionPane.INFORMATION_MESSAGE);

* 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,scrollPane,0,0,0,1);
JDialog dlg = new JDialog(parent, "Test", true);
dlg.getContentPane().setLayout(new BorderLayout());
dlg.getContentPane().add(BorderLayout.CENTER, pmain);
dlg.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dlg.setSize(800,500);
dlg.setAlwaysOnTop(true);
dlg.setVisible(true);      
Avatar of T_Shah

ASKER

Thnaks for reply.
dlg.setAlwaysOnTop(true);

This method is not available in 1.4.2_06
ASKER CERTIFIED SOLUTION
Avatar of UrosVidojevic
UrosVidojevic
Flag of Serbia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial