United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4373575 : html labels vanish from JTree with Windows L&F

Details
Type:
Bug
Submit Date:
2000-09-24
Status:
Resolved
Updated Date:
2000-11-17
Project Name:
JDK
Resolved Date:
2000-11-17
Component:
client-libs
OS:
windows_nt
Sub-Component:
javax.swing
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.3.0
Fixed Versions:
1.4.0 (beta)

Related Reports

Sub Tasks

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


                                     
2004-06-14
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
                                     
2000-10-26
WORK AROUND

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



Hardware and Software, Engineered to Work Together