• Post Reply Bookmark Topic Watch Topic
  • New Topic

JLabel for more than 1 line of text!  RSS feed

 
Dave Johnson
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.
 
Jose Botella
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
 
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!