It is very easy process to center a JFrame on screen. I have written following code for you. In the following code I have take size of screen and then I have divide size of the screen to half. After this I have made some adjustment to center a JFrame on screen. It is very simple code. Just try to understand it.
Code:
ds = Toolkits.getDefaultToolkit().getScreenSize();
fsw = this.getSize();
int xsw = (dsw.width - fsw.width) / 2;
int ysw = (dsw.height - fsw.height) / 2;
this.setBounds(xsw, ysw, fsw.width, fsw.height );
this.setSize( 500, 500 );
Bookmarks