Newbegi - JDialog (non modal) always on top

S

sent1729

Hi all,

In my application i would like to have the Jdialog always on top
without setting the modal property as true. I referred to one solution
provided in this forum which said: "to make the dialog a WindowListener
to itself and then call this.toFront() in the windowDeactivated()
method".

Well, this soultion works, but it always closes as opens the dialog
with in a fraction of a second. In other words, if I click on the
parent Frame, I see the dialog flickering before appearing on the
screen. I think this happens because I am bringing the Jdialog to front
when the JDialog window is deactivated. Is there any othe work around
the would just keep the JDialog on top of the frame without having to
bringing it to front.

Any help is grealy appreciated.

Thanks
Nathan.
 
K

Kevin

Set the dialog's parent window to the jframe, and set its modal as
false.
Is that what you want? (kind of like a floating toolbar)
 
S

sent1729

yes, i tried that, but when i click the parent frame the Dialog
disappears or is deactivated.
How to make it stay on top even if I click the parent frame?

Thanks
Nathan
 
S

Steve W. Jackson

yes, i tried that, but when i click the parent frame the Dialog
disappears or is deactivated.
How to make it stay on top even if I click the parent frame?

Thanks
Nathan

Nobody knows what you're talking about when you don't bother quoting any
portion of the previous post(s) unless they happen upon the entire
thread. Learn to quote (and properly).

You need to decide what behavior you're really trying to get. The
previous respondent told you to set the JDialog's owner to a particular
JFrame and set it non-modal. That gives you what you seem to have asked
for -- the dialog is always on top of the specified JFrame and it isn't
modal, meaning you can interact with the JFrame. It can not disappear
unless you close it. If it disappears when you click on the JFrame,
then you haven't set that frame as its owner. It can lose focus -- but
if it couldn't, you would not be able to interact with the underlying
JFrame while keeping it visible.

= Steve =
 
A

atom

I think this is what you are looking for ...

JDialog newdialog = new JDialog(yourJFrame, "Dialog that is always on
top!", false);
newdialog.setAlwaysOnTop(true);
newdialog.setVisible(true);

This will create a new JDialog and make it stay on top even when you
click the JFrame under it.

Adam
 
S

sent1729

Adam,

Im using eclipse 3.1 as my IDE, and in my code if I try to set the
setAlwaysOnTop property of JDialog to true, it says the method
setAlwaysOnTop is undefined for the JDialog.

Nathan
 
A

atom

Nathan,

make sure that you are doing this import...

import javax.swing.JDialog;

I use Netbeans 4.1 and have written several apps that use
setAlwaysOnTop, I use a check box with a mouse listener that the user
can change the always on top property of the dialog or frame with a
click.

another thing that might help is if you boil it down to a sample and
post the code.

Adam
 
M

Monique Y. Mudama

Nathan,

make sure that you are doing this import...

import javax.swing.JDialog;

I use Netbeans 4.1 and have written several apps that use
setAlwaysOnTop, I use a check box with a mouse listener that the
user can change the always on top property of the dialog or frame
with a click.

Maybe he's using 1.4? I don't see it in the javadocs for 1.4.
 
S

Steve W. Jackson

Monique Y. Mudama said:
Maybe he's using 1.4? I don't see it in the javadocs for 1.4.

That's because it's not in there until 1.5. But I'm inclined to
completely ignore these guys since they insist on not quoting anything
and using this group as their own private message exchange.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top