Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Locating Java Dialogs relative to a Browser Window

 
Bob Novak
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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
 
Shashank Agarwal
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic