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
T_ShahAsked:
Who is Participating?
 
UrosVidojevicConnect With a Mentor Commented:
Source:

http://forum.java.sun.com/thread.jspa?threadID=640621&messageID=3765440

        addWindowListener(new WindowAdapter() {
            public void windowDeactivated(WindowEvent we) {
                toFront();
            }
        });

Try this code, user from that forum says that worked for him, however on my platform it doesn't work.
0
 
UrosVidojevicCommented:
You can use JFrame component (which contains panel and other components you mentioned) instead of null. Is it acceptable?
0
 
UrosVidojevicCommented:
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.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
objectsCommented:
> 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?
0
 
T_ShahAuthor Commented:
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
0
 
objectsCommented:
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.
0
 
UrosVidojevicCommented:
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);      
0
 
T_ShahAuthor Commented:
Thnaks for reply.
dlg.setAlwaysOnTop(true);

This method is not available in 1.4.2_06
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.