• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDialog (non-modal) always on top

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a way to force a JDialog (non-modal) to always be on top??
Thanks,
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wouldn't that, by definition, be a modal dialog?
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic