Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JLabel and JScrollPane

 
Cyrus Serrano
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

can i display multiple line of text using a JLabel. Or do i need to paste the JLabel within a JScrollPane?

thanks
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use this method...

JLabel myLabel = new JLabel("<HTML> My Label text<br>Goes here</HTML>");

Cheers,
Rachel
 
Cyrus Serrano
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks mam rachel,

but is there any propoerties on JLabel that could multiline the text to be shown on that object, im sorry to compare it on Visual Basics Label object. thanks mam.

im currently trying to Quiz program, questions are displayed on label objects, problem is , it just display a single line. help..

Cyrus
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use an non-editable JTextArea and make it look like a label. JTextArea supports word-wrap
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a much easier solution to use. In our project we are reading label definitions from a properties file that contains different translations at using a text area is far easier than the HTML label because we can't be sure of the size of thing that we have to fit onto the label.

Cheers,
Rachel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic