-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.3.0
-
None
-
x86
-
linux
As of Swing 1.1.1 I believe, it is supported to use HTML text wherever Swing normally accepts a displayable string; beginning the string with "<html>" causes it to be parsed and displayed as HTML. However, the base font used in the HTML does not match the font used for non-HTML text in the same kind of component; furthermore, it appears to be insensitive to the fonts given by UIDefaults as the defaults for that component type. This means that it is unacceptable in UI terms to actually mix HTML and non-HTML labels in a single display (and marginally acceptable to use all HTML).
For example, when displaying a JTree, you might wish to use HTML to mark certain tree nodes in color. Or you might wish to display certain tooltips as multiple lines; the Swing team recommends using HTML and the <BR> element to accomplish this. But when this is done, the HTML labels are in a conspicuously different (and depending on the JDK, sometimes uglier) font than the plain labels. If you are using UIDefaults to choose a slightly different standard font than the Swing defaults (Forte for Java IDE, for example, normally selects 11-pt and not 12-pt text, with black rather than bluish foreground), plain tree labels (and similar UI components) will appear in the desired application default, while HTML labels may differ drastically in appearance.
Perhaps it would be possible to use <FONT> tags in each and every HTML label to select a basefont equivalent to that used on plaintext labels. But this could (1) possibly affect performance to have all of those extra tags (consider a large tree structure with hundreds of nodes), (2) imposes a burden on the application developer to find HTML tags which produce an effect similar to those of the UIDefaults, and ensure that all HTML text in the application is prefixed with them--which increases the maintenance cost of the application and complicates implementation of user-settable UI defaults. If HTML labels were more sensibly defaulted as regards basefont/color/etc., this feature would be more practical and helpful.
I am attaching a JAR (java -jar $file) which demonstrates the problem and includes source. It creates two JTree's, one with default UIDefaults, one with customized UIDefaults. In each, there are some plaintext nodes and an HTML node, differing only in using <FONT COLOR=red> to change the color. Screenshots from Windows 2000 (JDK 1.3 FCS) and RH Linux with Gnome/Enlightenment (JDK 1.3 FCS) also attached.
For example, when displaying a JTree, you might wish to use HTML to mark certain tree nodes in color. Or you might wish to display certain tooltips as multiple lines; the Swing team recommends using HTML and the <BR> element to accomplish this. But when this is done, the HTML labels are in a conspicuously different (and depending on the JDK, sometimes uglier) font than the plain labels. If you are using UIDefaults to choose a slightly different standard font than the Swing defaults (Forte for Java IDE, for example, normally selects 11-pt and not 12-pt text, with black rather than bluish foreground), plain tree labels (and similar UI components) will appear in the desired application default, while HTML labels may differ drastically in appearance.
Perhaps it would be possible to use <FONT> tags in each and every HTML label to select a basefont equivalent to that used on plaintext labels. But this could (1) possibly affect performance to have all of those extra tags (consider a large tree structure with hundreds of nodes), (2) imposes a burden on the application developer to find HTML tags which produce an effect similar to those of the UIDefaults, and ensure that all HTML text in the application is prefixed with them--which increases the maintenance cost of the application and complicates implementation of user-settable UI defaults. If HTML labels were more sensibly defaulted as regards basefont/color/etc., this feature would be more practical and helpful.
I am attaching a JAR (java -jar $file) which demonstrates the problem and includes source. It creates two JTree's, one with default UIDefaults, one with customized UIDefaults. In each, there are some plaintext nodes and an HTML node, differing only in using <FONT COLOR=red> to change the color. Screenshots from Windows 2000 (JDK 1.3 FCS) and RH Linux with Gnome/Enlightenment (JDK 1.3 FCS) also attached.
- duplicates
-
JDK-4349637 HTML text in JLabel does not use LnF's font
-
- Resolved
-