Results 1 to 5 of 5
  1. #1
    Bestsanchez is offline Member
    Join Date
    Jan 2012
    Location
    The Coffee Pot
    Posts
    36
    Rep Power
    0

    Default JLabels on JPanel in wrong spot

    Sorry for all the threads lately this is my last for a while I promise
    JLabels on JPanel in wrong spot-hangman.jpg

    My hangman game is almost finished, it's just that these black labels, where the text inside turns white when they correctly guess, are bugging me because they're supposed to be where the checkmark is(the squares at the very top and bottom are my buttons, ignore them). I know a good amount about layout managers and stuff and have played around with it a bunch but it just screws it up more. Right now the letters are showing up where the red X is and it works, but it's not what I want. Details: 3 panels(top button row, bottom button row, and middle panel with drawing and letters), i'm using borderlayout for the jframe, and tried using it for positioning labels on middle panel. Another thing: are even jlabel backgrounds possible so they can't figure out the letter by looking at the width of the jlabel(as seen in the 'red X' row). All help appreciated thanks!

    EDIT: Oh yeah and sorry no code because it's pretty long. Unless you really want it.
    Last edited by Bestsanchez; 01-16-2012 at 07:28 AM.

  2. #2
    switch's Avatar
    switch is offline Member
    Join Date
    Jan 2012
    Location
    U.S.A.
    Posts
    19
    Rep Power
    0

    Default Re: JLabels on JPanel in wrong spot

    I would get rid of the black labels and set the label text to = new JLabel(""); blank. When they guess correct use jlabelname.setText("x"); and it will appear. When they start a new game reset the label to (""); again. You could try using a blank label on the ends or end to move the letter over since your using borderlayout. GridbagLayout allows you to add columns and rows according to an x, y grid. Upper left corner of the screen, frame or pane is x = 0, y = 0. The origin of the number line. x is horizontal (right ascending positive) and y is vertical (down ascending positive).

    switch

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: JLabels on JPanel in wrong spot

    Your middle JPanel should use BorderLayout, and the image JPanel should be placed BorderLayout.CENTER. The JPanel with the letter JLabels in it should go to the BorderLayout.SOUTH position (or perhaps better to call it BorderLayout.PAGE_END). This south JPanel could actually be two JPanels nested together, the outer one using FlowLayout and the inner one using GridLayout(1, 0, x, 0), where x is the gap between JLabels.

  4. #4
    Bestsanchez is offline Member
    Join Date
    Jan 2012
    Location
    The Coffee Pot
    Posts
    36
    Rep Power
    0

    Default Re: JLabels on JPanel in wrong spot

    I actually figured this out last week by using a mix of GridBagLayout and BorderLayout, but thanks.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: JLabels on JPanel in wrong spot

    Quote Originally Posted by Bestsanchez View Post
    I actually figured this out last week by using a mix of GridBagLayout and BorderLayout, but thanks.
    Thanks for letting us know, very glad you've got it working, and best of luck with this and your other projects!

Similar Threads

  1. Drawing on wrong JPanel.
    By RogerWilco in forum AWT / Swing
    Replies: 8
    Last Post: 01-13-2012, 10:41 PM
  2. updating a gameBoard (JPanel filled with JLabels)
    By Bloitz in forum AWT / Swing
    Replies: 3
    Last Post: 07-07-2011, 07:31 PM
  3. Replies: 5
    Last Post: 03-05-2011, 01:43 AM
  4. JPanel and JLabels Not Repainting
    By phosphide in forum AWT / Swing
    Replies: 6
    Last Post: 11-13-2010, 04:17 AM
  5. Replies: 6
    Last Post: 06-16-2010, 07:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •