Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How to set JFrame and JDialog to appear centered on the screen

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

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


  2. #2
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: How to set JFrame and JDialog to appear centered on the screen

    Quote Originally Posted by Steven1983 View Post
    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
    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().
    Then you can invoke setLocationRelativeTo(null); that centers the frame/dialog on the screen (null means "the screen").
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

Similar Threads

  1. Need some help with this JFrame, or JDialog.
    By MR bruto in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 10th, 2013, 08:14 AM
  2. different between japplet, jframe, jdialog, jwindow, jpanel
    By hwoarang69 in forum AWT / Java Swing
    Replies: 1
    Last Post: October 27th, 2012, 10:53 PM
  3. Replies: 1
    Last Post: April 30th, 2012, 08:16 AM
  4. JDialog from JFrame button (GUI)
    By Jameseyboy in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 5th, 2012, 07:55 AM
  5. how to set my frame in the middle of the screen
    By chronoz13 in forum AWT / Java Swing
    Replies: 3
    Last Post: February 10th, 2012, 08:13 AM

Tags for this Thread