?
Solved

JDialog always on top

Posted on 2007-10-06
8
Medium Priority
?
779 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:T_Shah
  • 4
  • 2
  • 2
8 Comments
 
LVL 7

Expert Comment

by:UrosVidojevic
ID: 20027842
You can use JFrame component (which contains panel and other components you mentioned) instead of null. Is it acceptable?
0
 
LVL 7

Expert Comment

by:UrosVidojevic
ID: 20027889
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
 
LVL 92

Expert Comment

by:objects
ID: 20028749
> 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:T_Shah
ID: 20029255
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
 
LVL 92

Expert Comment

by:objects
ID: 20029283
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
 
LVL 7

Expert Comment

by:UrosVidojevic
ID: 20029522
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
 

Author Comment

by:T_Shah
ID: 20031243
Thnaks for reply.
dlg.setAlwaysOnTop(true);

This method is not available in 1.4.2_06
0
 
LVL 7

Accepted Solution

by:
UrosVidojevic earned 375 total points
ID: 20031425
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month16 days, 13 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question