How to set JFrame and JDialog to appear centered on the screen
I have developed an application in Java in Netbeans IDE. My application uses one JFrame and some JDialogs.The problem that I have is that when I run the application both JFrame and JDialogs shown in the upper left corner of the screen but i would like to appear on the center. I searched on the internet and i have found code to do this but it did not work. Please, can you tell me how it's done to show forms in the center of the screen.
Thank you very much for your time.
Re: How to set JFrame and JDialog to appear centered on the screen
First, you have to set the size of JFrame/JDialog. This can be done setting explicitly the size using setSize method or implicitly using a pack().
Originally Posted by Steven1983
Then you can invoke setLocationRelativeTo(null); that centers the frame/dialog on the screen (null means "the screen").