Skip to content
Advertisement

JLabel HTML4 support

My question is if JLabel (java swing) supports html4 and css2. I know, it supports html3.2 but I want newer version.

Or is there another way to display html4 on a jPanel.

Advertisement

Answer

In short: no; HTML 3 only, before CSS.

The “HTML” supported by JLabel, JButton, etc, is things like <font color="" face="" /> and <a href="#"> to provide inline styling of label textual content.

To indicate that an HTML supporting component contains HTML, the string value must be wrapped in "<html></html>"; this is for backward compatibility with existing code. For example:

button = new JButton("<html><b><u>T</u>wo</b><br>lines</html>");

Further information can be seen here: http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JLabel.html and documentation here: http://docs.oracle.com/javase/tutorial/uiswing/components/html.html

JLabel does not provide an implementation of the CSS 2.x visual formatting model, so HTML4 style=”” attributes and CSS box formatting will not work. If you want rich HTML formatting support then you’ll need to use a web-browser component.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement