How to center your application on the screen?
291 views To center your application you can do this:
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int w = this.getSize().width;
int h = this.getSize().height;
int x = (screenSize.width-w)/2;
int y = (screenSize.height-h)/2;
this.setLocation(x, y);
Or the way that I prefer to do it:
setLocationRelativeTo(null);
Both ways work fine and will center the application on your screen.

(1 votes, average: 4 out of 5)
(2 votes, average: 4.5 out of 5)




