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 3 of 3

Thread: Weird thing with JFrame

  1. #1
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Weird thing with JFrame

    I noticed something weird when I was using JFrame. When ever I type:
    JFrame f = new JFrame();
    f.setSize(640,480);

    The part that you can draw to isn't actually 640x480. I'm going to assume that this is because of the top-bar and the side borders. How can I set the drawing portion to exactly 640x480?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Weird thing with JFrame

    I believe the sizes of the title bar and borders of a JFrame are platform dependent, and I am not sure you can retrieve those dimensions (unless perhaps you create your own default look and feel - and even then I'm not sure how to do it). However, if you specify the dimensions of the main JPanel you add to the JFrame you can guarantee the drawable region is the dimension you want
    JFrame f = new JFrame();
    f.getContentPane().setPreferredSize(new Dimension(640,480));
    f.pack();
    f.setVisible();

  3. The Following User Says Thank You to copeg For This Useful Post:

    Brt93yoda (August 23rd, 2010)

  4. #3
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Weird thing with JFrame

    Thanks alot!

Similar Threads

  1. ClassNotFoundException (bit weird)
    By chronoz13 in forum Exceptions
    Replies: 1
    Last Post: April 26th, 2011, 02:15 AM
  2. Stupid thing can't find image icon right in front of it!!!
    By javapenguin in forum What's Wrong With My Code?
    Replies: 14
    Last Post: July 9th, 2010, 01:02 AM
  3. Trying 3 different ways to do the same thing, each one is wrong
    By shemer77 in forum What's Wrong With My Code?
    Replies: 14
    Last Post: June 4th, 2010, 07:01 PM
  4. Jsp weird problem
    By johniem in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: February 5th, 2010, 06:46 AM
  5. Weird issue with while loop ending/being skipped
    By ang3c0 in forum Loops & Control Statements
    Replies: 4
    Last Post: December 25th, 2009, 12:09 PM