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.


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

Results 1 to 2 of 2

Thread: Content positioning on the screen

  1. #1
    Junior Member
    Join Date
    Jul 2009
    Thanked 0 Times in 0 Posts

    Question Content positioning on the screen

    Hi I'm making a game and I am having some issues with positioning some JLabels on the screen. I might just not know enough about how the positioning works but this is what is going on. My application runs center screened I have that much done correctly. I have all of my JLabels displaying now and I can set them where I want them but it takes much tweaking and when I change my screen resolution nothing is where it should be in my JFrame. I would like for things to be where they should be for anyone using any resolution.

    imgBackingPanel.setBounds(((screenSize.width / 2)-6), ((screenSize.height /2)+116), 230, 52);
    Thanks Helloworld922. I took out the equation completely and found that indeed the child component's position is based off of the parent component's position. So I needed no equation to position them within the JFrame. I changed resolutions to test it out and voila it worked like a charm.

    imgBackingPanel.setBounds(570, 548, 230, 52);
    Last edited by Drakenmul; July 27th, 2009 at 02:29 PM. Reason: Issue Resolved

  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Thanked 619 Times in 561 Posts
    Blog Entries

    Default Re: Content positioning on the screen

    I'm not completely positive, but I think JComponent's coordinates are mapped from their parent, not the whole screen. So, if you wanted to draw to the left, use
    imgBackingPanel.setBounds(((screenSize.width / 2)-6), 0, 230, 52);

Similar Threads

  1. Java program for downloading contents from the web
    By alley in forum Java Networking
    Replies: 8
    Last Post: June 17th, 2009, 01:13 PM
  2. Drawing "Hello world" on screen
    By shikh_albelad in forum Java SE APIs
    Replies: 4
    Last Post: June 11th, 2009, 03:21 AM
  3. How to display the contents of my queue?
    By rocafella5007 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 30th, 2009, 11:46 AM
  4. Java program for remote host screen capture
    By krishnaraoveera1294 in forum Java Networking
    Replies: 1
    Last Post: March 13th, 2009, 04:53 AM