File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes about Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "about "pop up center"" Watch "about "pop up center"" New topic
Author

about "pop up center"

James Du
Ranch Hand

Joined: Mar 23, 2001
Posts: 186
Hi, all
i wonder if there's any decent way to pop up the windows in the center of the screen? how do you guys achieve that?
thanks
James
Scott Franklin
Greenhorn

Joined: May 21, 2002
Posts: 4
Use Toolkit.getDefaultToolkit().getScreenSize() to get the screen size, getSize() to get the frame size, and setLocation() to move the screen to the desired location.
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
In your JDialog constructor, add the line below:
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

Sai,
That's very nice and sweet, I was doing something like this evry time:

I guess there is no need for it whatsoever.
Eugene.
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

setLocationRelativeTo(null);

Sai,
Actually, it works for JDialog, but the method is not defined for JFrame. Is there an equivalent?
Thanks,
Eugene.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Is JDialog a subclass of JFrame? Look at the classes that are it's parents.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
Eugene,
Sorry. I wish there is one for the JFrame. You have the set absolute position for the JFrame.
James Du
Ranch Hand

Joined: Mar 23, 2001
Posts: 186
Thanks you all, i wonder why sun not encapsulate that function of the class JFrame into a method , since it's so common and widely-demanded
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
It turns out that the setLocationRelativeTo() is a new addition to java.awt.Window (and consequently to JFrame) in JDK 1.4.
This addition actually makes perfect sense, and I think that up to 1.4, that method implementation was simply in the wrong place (JDialog instead of its immediate parent) and that's why it didn't work for JFrame.
Eugene.
 
GeeCON Prague 2014
 
subject: about "pop up center"