Results 1 to 5 of 5
Thread: JLabels on JPanel in wrong spot
- 01-16-2012, 06:13 AM #1
Member
- Join Date
- Jan 2012
- Location
- The Coffee Pot
- Posts
- 36
- Rep Power
- 0
JLabels on JPanel in wrong spot
Sorry for all the threads lately this is my last for a while I promise
-.gif)

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 06:28 AM.
- 01-25-2012, 03:39 PM #2
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
-
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.
- 01-26-2012, 01:10 AM #4
Member
- Join Date
- Jan 2012
- Location
- The Coffee Pot
- Posts
- 36
- Rep Power
- 0
Re: JLabels on JPanel in wrong spot
I actually figured this out last week by using a mix of GridBagLayout and BorderLayout, but thanks.
-
Re: JLabels on JPanel in wrong spot
Similar Threads
-
Drawing on wrong JPanel.
By RogerWilco in forum AWT / SwingReplies: 8Last Post: 01-13-2012, 09:41 PM -
updating a gameBoard (JPanel filled with JLabels)
By Bloitz in forum AWT / SwingReplies: 3Last Post: 07-07-2011, 06:31 PM -
How can I add JLabels, JButtons, JTextFields to a JPanel then JFrame?
By crazysketch in forum New To JavaReplies: 5Last Post: 03-05-2011, 12:43 AM -
JPanel and JLabels Not Repainting
By phosphide in forum AWT / SwingReplies: 6Last Post: 11-13-2010, 03:17 AM -
new JLabels not showing in JPanel (doing revalidate&repaint)
By r00tb33r in forum AWT / SwingReplies: 6Last Post: 06-16-2010, 06:03 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks