JDK-4373575 : html labels vanish from JTree with Windows L&F
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2000-09-24
  • Updated: 2000-11-17
  • Resolved: 2000-11-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.0 betaFixed
Description

Name: krC82822			Date: 09/24/2000


24 Sep 2000, eval1127@eng -- reproducible on NT 4.0, with 1.3.0-C, with Win L&F (works fine under Metal).  Couldn't find existing bug covering this issue.  

D:\jb\src>java -version
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

Html format labels in JTree with the Windows look and feel vanish when you
click on the lable above. To reproduce, run the attached Java application and
click on the JTree nodes labelled "three", "two", and "one", in that order.

import java.awt.Container;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.UIManager;
/** Check out tree, because we seem to lose labels with the Windows look and
feel */
class SimpleTree
{
  private static String block(String s)
  {
    return "<html>" + s + "</html>";
  }
  public static void main(String[] s) throws Exception
  {
    System.err.println("To reproduce, click on the nodes marked three, two, one
in that order");
    UIManager.setLookAndFeel
("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    JFrame jf = new JFrame();
    DefaultMutableTreeNode top = new DefaultMutableTreeNode(block("top"));
    DefaultMutableTreeNode one = new DefaultMutableTreeNode(block("one"));
    one.add(new DefaultMutableTreeNode(block("oneChild")));
    top.add(one);
    DefaultMutableTreeNode two = new DefaultMutableTreeNode(block("two"));
    top.add(two);
    two.add(new DefaultMutableTreeNode(block("twoChild")));
    DefaultMutableTreeNode three = new DefaultMutableTreeNode(block("three"));
    three.add(new DefaultMutableTreeNode(block("threeChild")));
    top.add(three);
    JTree jt = new JTree(top);  // same results with "new JTree(new DefaultTreeModel(top))"
    Container cp = jf.getContentPane();
    cp.add(jt);
    jf.pack();
    jf.setVisible(true);
  }
}
(Review ID: 109724) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin-beta FIXED IN: merlin-beta INTEGRATED IN: merlin-beta
14-06-2004

EVALUATION This is happening because of DefaultTreeCellRenderer's special handling of its font. It basicly keeps the font null, unless expclitly set. The font from the JTree is then normally picked up do to the containment hierarchy. But the html support uses the font from the component, and only looks it up once (this normally isn't a problem as the html is normally updated when the font changes (renderers override firePropertyChangeEvent)) so that in certain situations the font looked up is null, and thus causes this wierd font change behavior. scott.violet@eng 2000-10-26
26-10-2000

WORK AROUND Explicitly set the font of the Renderer. scott.violet@eng 2000-10-26
26-10-2000