Java Code for my Program

Asked By 10 points N/A Posted on -
qa-featured

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..

SHARE
Best Answer by Chung Opi
Best Answer
Best Answer
Answered By 5 points N/A #99112

Java Code for my Program

qa-featured

In programming language you can do many different things and also create frame. Just go to this link and try this code, hope you will able to have frame on the center of screen, https://alvinalexander.com/blog/post/jfc-swing/how-center-jframe-java-swing. In creating frame take care of the dimension in your code, you can do this as you desire. Along with the frame option you can also find the other options on this link.

Try this link, http://www.javacoffeebreak.com/books/extracts/javanotesv3/c7/s7.html you want to know each and every thing about the frame in java language. It will help you in creating different types of frame and dialog boxes. Hope you come up with the solution.

Answered By 0 points N/A #195421

Java Code for my Program

qa-featured

 

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.

Related Questions