• Post Reply Bookmark Topic Watch Topic
  • New Topic

2 lines of text for a label?  RSS feed

 
Dave Johnson
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted to know if it is possible for 1 Label or JLabel to print more than 1 line of text.
For example:
Dave Johnson
would become;
Dave
Johnson

I know that I could just have 2 Labels but that wouldn't work for what I am trying to do.
Any ideas?
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A quick and dirty solution is to use HTML for the label text:
JLabel aLabel = new JLabel("<html><b>Two<br>lines</html>");
 
Dave Johnson
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No good Joe, the program is not an applet. Good idea though!
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The program does not need to be an applet.
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use HTML to format the text on lots of Swing components, applet or no. Check the
Java Tutorial.
 
Dave Johnson
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Joe I misunderstood you, many thanks for your help.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!