Asked By
aldiaz
10 points
N/A
Posted on - 04/01/2012
Hi there JAVA Experts.
I really need your help so that I can finished my program today.
I want to display the Frame I created at the center of the monitor  after opening it.
Does anyone have a code for this..?
I really need it ASAP..
Java Code for my Program
Â
Hi Aldiaz,
Â
You can use any of the below code snipet to display the frame you created in the centre of the screen.
Â
JFrame.setLocationRelativeTo(null)
Â
// This means we can set the location of the frame relative to any other frame or window etc. Null means it will be placed in the centre of the screen and is relative to no other component
Â
or
Â
JFrame.setLocation((screenWidth-frameWidth)/2,(screenHeight-frameHeight)/2);
Â
// This means setting the location as X and Y coordinates. [screenWidth-frameWidth)/2] will give you the centre coordinate of X and [screenHeight-frameHeight)/2] will give you centre coordinate of screen Y
Â
Hope it helps.