• 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

Locating Java Dialogs relative to a Browser Window

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an applet that pops up confirmation dialogs, etc. while running. If the user does not move the Browser the following works:

1. Get the "frame" for the applet
Window w = SwingUtilities.windowForComponent( MapApplet.this );
mFrame = (Frame) w;
2. Use the frame as the parent for the JOptionPanes - e.g.
mParent = MapApplet.getFrame();
JOptionPane.showConfirmDialog(mParent, theMessage, theTitle,
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);

Now, I'd like to make this dynamic so if the user moves the browser, I can get the new frame parameters and keep the pop-ups centers. I tried calling the code in 1 within a static method on the applet and then returning the window value cast as a frame, but that is NOT working (the location is always relative to the browser window....)

So, I thought of using java-javascript to get the location of the browser window and using that to create a Frame I could center on. But, I can't come up with the right properties to get from the window JSObject I can get from within the applet:

jsWindow = JSObject.getWindow(this);

i.e. what members to I try to get from the jsWindow?

Any help would be greatly appreciated - including another way to accomplish the basic task of centering applet pop-ups on the current browser window.

Thanks
Bob
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use the getLocation() and the setLocation methods to do this. Using windows listener, get the location of the browser window. Now set the location of the dialog by calculating the center for the obtained axis positions. Also, you may set the dialog as a modal dialog (one wherein the user cannot work around with the main application if the dialog is on). Then, u'll not have to worry about the changing locations.
 
reply
    Bookmark Topic Watch Topic
  • New Topic