4

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.

kleopatra
  • 51,061
  • 28
  • 99
  • 211
nask00s
  • 97
  • 1
  • 8
  • I can't even find *any* official documentation on the HTML support in Swing ... All there seems to be is the page in the Java Tutorials which doesn't really contain much info apart from a short introduction. – Joey Jun 17 '12 at 19:12
  • why not check for yourself ...just test it create your own label with some html4? :) – David Kroukamp Jun 17 '12 at 19:23
  • Of course I tried it and then I searched about it, but all I found was nothing, Only one guy in a forum had the same question and he didn't get any answer. – nask00s Jun 18 '12 at 10:46

1 Answers1

7

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.

Lawrence Dol
  • 63,018
  • 25
  • 139
  • 189
Dai
  • 141,631
  • 28
  • 261
  • 374
  • Thank you for your fast response! But do you know any good web-browser component? and can I use it only to display html from a String (I mean not to load a webpage or open an html document) – nask00s Jun 18 '12 at 10:49
  • 1
    There's a variety of browser components that work with Swing: http://stackoverflow.com/questions/145863/best-java-swing-browser-component . You can provide raw HTML within a String object to these components fine (as well as by downloading a page or manipulating the DOM yourself). – Dai Jun 18 '12 at 14:15