Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

JFrame in the middle of the screen

  Asked By: Kevin    Date: Apr 21    Category: Java    Views: 1707
  

Anyone know how to run the JFrame in the middle of the screen ?
In the Delphi, I used to code this way :

Form1.left := round((Screen.Width - Form1.left)/2);
Form1.top := round((Screen.Height - Form1.height)/2);

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Vicki Fields     Answered On: Apr 21

Use the Toolkit object to get the screen  size.

Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screen = kit.getScreenSize();
frame.setBounds(screen.width/4,screen.height/4, screen.width/2,
screen.height/2);

or use the frame.setLocation() method instead of setBounds()
frame.pack();
frame.setLocation((screen.width-frame.getWidth())/2, (screen.height-
frame.getHeight())/2);

 
Didn't find what you were looking for? Find more on JFrame in the middle of the screen Or get search suggestion and latest updates.




Tagged: