wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes JDialog (non-modal) always on top Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JDialog (non-modal) always on top" Watch "JDialog (non-modal) always on top" New topic
Author

JDialog (non-modal) always on top

Duane Riech
Ranch Hand

Joined: Feb 27, 2003
Posts: 52
Is there a way to force a JDialog (non-modal) to always be on top??
Thanks,
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Wouldn't that, by definition, be a modal dialog?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I think what he is referring to is needing to have a Window open that is always on top, but you still have access to the other Windows.
I don't believe there is really a way to do this with JFrames/JDialogs without attachting a focus listener on the JDialog and when it loses focus, move it to the front of all the other windows. This will cause flickering and works pretty horribly.
I don't know the requirements of your application, but if you could make it an MDI app, JInternalFrames are able to be put on the Palette Layer of a JDesktopPane which will give you the results you want. Just not in a Window outside of the main app.


GenRocket - Experts at Building Test Data
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Originally posted by Gregg Bolinger:
I think what he is referring to is needing to have a Window open that is always on top, but you still have access to the other Windows.

You do a better job at reading into requirements than I. Your suggestion of an MDI app reminds me of a trick I used trying to simulate modal dialogs on an JApplet (there was something funky with JApplets and modal dialogs I guess. . .). Add an InternalFrame to the GlassPane rather than the ContentPane of a JApplet (applies to JFrame or JWindow as well). Set the GlassPane as a mouse listener and it intercepts any attempt to access the components on a ContentPane. The effect is that of a modal dialog within the application. When the dilaog is closed, remove the mouse listener from the GlassPane and clicks will be available to the ContentPane components. Maybe that's another option.
Duane Riech
Ranch Hand

Joined: Feb 27, 2003
Posts: 52
The reason for the question was in reference to a drag and drop
implementation from a JTable to a JDialog. Since the JDialog would
be covered once the dragsource was clicked on, I wanted a way to
force the JDialog to stay on top as the dragTarget.
I implemented a "class ComponentEvent extends ComponentAdapter"
and included the componentHidden() method to trap hidding the JDialog
and included the addComponentListener(new ComponentEvent()); line in
the JDialog public constructor. I wanted to make a call to toFront(),
but I'm not trapping the Hidden event for some reason.

Either way, I'm sure there's another way of dealing with the issue.
Thanks for the responses.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDialog (non-modal) always on top
 
Similar Threads
How can i hide a JFrame from showing a window in the taskbar?
JDiaog window remain always on top
modal dialog always on top
Modal JWindow
Modal JWindow