my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes Setting placement of JDialog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Setting placement of JDialog" Watch "Setting placement of JDialog" New topic
Author

Setting placement of JDialog

Jessica Dancel
Greenhorn

Joined: Dec 07, 2006
Posts: 10
I have a modal JDialog that I pop up from a parent window. Right now it's appearing in the upper left corner of the screen. I'd like it to pop up centered over the parent window, but I can't find any methods to do this. Anyone know how?
Thanks in advance.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
specify the parent when you construct the dialog
Jessica Dancel
Greenhorn

Joined: Dec 07, 2006
Posts: 10
Okay, here's my code:



Anyone have a thought as to how to get myDialog centered over the instance of PanelClass? Thanks.

Jessica Dancel
[ January 03, 2007: Message edited by: Jessica Dancel ]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Originally posted by Jessica Dancel:
myDialog = new DialogClass(new Frame());


I'm guessing that the DialogClass constructor passes the parameter to the superconstructor.

If so, then you want to pass in the actual parent frame so the dialog's position can be taken from it, not a newly constructed Frame object with which nothing else is done.


bitguru blog
Jessica Dancel
Greenhorn

Joined: Dec 07, 2006
Posts: 10
Thanks, guys. This gave me what I needed.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting placement of JDialog
 
Similar Threads
fix JDialog position relative to its parent JFrame component
Refreshing Parent Window from Child
How to update a row in view if i sort a column in my model?
Popup window jsp page
Losing session data on closing a pop up window and refreshing the parent