Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about "pop up center"

 
James Du
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your JDialog constructor, add the line below:
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is JDialog a subclass of JFrame? Look at the classes that are it's parents.
Mark
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eugene,
Sorry. I wish there is one for the JFrame. You have the set absolute position for the JFrame.
 
James Du
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic