Reputation: 559
Hi I am developing an desktop application using swing when i am executing the frame window it is displaying at the left side bottom of my screen can i customize that and display at in center of the screen?
Upvotes: 1
Views: 191
Reputation: 3
Following Code will provide you Width and Height of Your Screen
Toolkit toolkit=Toolkit.getDefaultToolkit();
toolkit.getScreenSize().width
toolkit.getScreenSize().height
Then Using This Height and Width You can set where to position Your frame with following function
this.setLocation(int x, int y)
//first variable x is position relative to left top of ur screen in horizontal direction
// second variable y is position relative to left top in vertical direction
Upvotes: 0
Reputation: 208974
"yes i am using gui builder"
Just put setLocationRelativeTo(null)
after initComponents()
, in the constructor.
public class MyFrame extends JFrame {
public MyFrame() {
initComponents();
setLocationRelativeTo(null);
}
}
JFrame
as a subclass of Window
inherits Window
methods. The API can be seen here The method used above is listed as follows
public void setLocationRelativeTo(Component c)
- Sets the location of the window relative to the specified component according to the following scenarios.Upvotes: 3