• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JLabel ..does it accept HTML ?

 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Beginning with Java SE 1.3, you can use both plain and HTML text in buttons, labels, and
menu items. We don’t recommend HTML in buttons—it interferes with the look and feel. But
HTML in labels can be very effective. Simply surround the label string with <html>. . .</html>,
like this:
label = new JLabel("<html>Required entry:</html>");
Fair warning—the first component with an HTML label takes some time to be displayed
because the rather complex HTML rendering code must be loaded."

Core Java Vol 1 (8th Ed) Pg. 380.



It seems to me that creating a label and passing HTML parameters did not make the item bold (attached scr.JPG - screenshot), however the tags were simply written
out on the label, so no HTML parsing was taking place.

Do I need to write some other code to enable parsing of HTML text?

scr.JPG
[Thumbnail for scr.JPG]
Screenshot
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding the <html>...</html> tags round the outside of the text, as the instructions you just copied tell you. The JLabel will treat it as plain text if you don't add that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic