This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDialog (non-modal) always on top

 
Duane Riech
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to force a JDialog (non-modal) to always be on top??
Thanks,
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't that, by definition, be a modal dialog?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic