Results 1 to 3 of 3
- 05-13-2011, 08:38 PM #1
Member
- Join Date
- May 2011
- Location
- Maryland
- Posts
- 38
- Rep Power
- 0
Need help with JPanels and JLabels
Hey,
Just a quick question about working with JLabels inside JPanels. I have a 2D array of JPanels (called squares) and would like to put a JLabel with text in some of them. However, when the text is too long to fit in one line of the box, it cuts off. I tried to put in "\n" in order to create a new line but when I ran the program java seemed to completely ignore it. Does anyone know how to either create new lines inside a JLabel or to make it start a new line once it has reached the edge of its display area? I have posted one example of a method in my program below just to clarify. Any help/advice is much appreciated!
public void display(){
squares[2][8].removeAll();
playerMoney = new JLabel(playerOne.getName() + " has: $" + playerOne.getCash() + "\n" + playerTwo.getName() + " has: $" + playerTwo.getCash());
squares[2][8].add(playerMoney);
squares[2][8].validate();
}
- 05-13-2011, 10:20 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
You can use HTML is a JLabel. Then you can use the "br" tag instead of a "\n" to control where the line splits.
Otherwise you could use a JTextArea which supports wrapping. You can play with the text area properties to make it look like a label.
- 05-13-2011, 10:43 PM #3
Member
- Join Date
- May 2011
- Location
- Maryland
- Posts
- 38
- Rep Power
- 0
Similar Threads
-
Switching JPanels with a button inside one of the JPanels
By Beastly in forum AWT / SwingReplies: 2Last Post: 04-26-2011, 02:50 PM -
Problems regarding JPanels in JPanels
By ColtonPhillips in forum AWT / SwingReplies: 2Last Post: 07-19-2010, 08:33 PM -
can i have a JList of Jlabels?
By chayan in forum AWT / SwingReplies: 3Last Post: 07-04-2010, 12:19 AM -
Overlapping JLabels
By techbossmb in forum AWT / SwingReplies: 3Last Post: 09-21-2009, 03:21 PM -
problem with JLabels
By geork in forum New To JavaReplies: 3Last Post: 01-31-2008, 02:30 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks