• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

JLabel for more than 1 line of text!

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is some code I am playing with:

There are other classes involved but they do not concern this matter.
All I want to do is alter my code so that subChoiceLabels[]can accept 2 lines of text from the array subChoices[][].
For example subChoiceLabels[0] would have 1 line of code as [b]Bitter in Bold font style and on the line below the text �2.04 per pint in non-bold font style.
I can't seem to find a way to create a label or textfield like this. Label or JLabel seems my best option.
Please help, thanks, Dave.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use html formatting in the string passed to a JLabel constructor: something like:
"<html><b>" + subChoices[0][0] + "</b><br>" + subChoices[0][1]
[ December 20, 2003: Message edited by: Jose Botella ]
 
Dave Johnson
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jose, that looks like what I was looking for. I can keep my array of string to loop with aswell. I am happy, thanks again, Dave.
 
Dave Johnson
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am I right in thinking that the only way to assign these strings to the JLabel is to do it by long-hand and not in a loop?
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make i to increment by two in the for loop and...
"<html><b>" + subChoices[num][i] + "</b><br>" + subChoices[num][i+1]
 
Dave Johnson
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help Jose
 
This is my favorite show. And this is my favorite tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!