Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes JLabel ..does it accept HTML ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JLabel ..does it accept HTML ?" Watch "JLabel ..does it accept HTML ?" New topic
Author

JLabel ..does it accept HTML ?

Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

"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?




[Thumbnail for scr.JPG]


Jon
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4369
    
    8

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.
 
Consider Paul's rocket mass heater.
 
subject: JLabel ..does it accept HTML ?