-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.4.1
-
x86
-
windows_nt
Name: gm110360 Date: 09/11/2002
FULL PRODUCT VERSION :
java version "1.4.1-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b14)
Java HotSpot(TM) Client VM (build 1.4.1-beta-b14, mixed mode)
FULL OPERATING SYSTEM VERSION : NT 4.0 SP6a
A DESCRIPTION OF THE PROBLEM :
In the following test program the action of expanding and
collapsing nodes in a large-model tree causes the tree to
be displayed incorrectly. When a node is expanded the
existing children are removed and a new set is added
in the tree expansion listener. This simulates a larger
program where the tree is expanded as the user drills
down, due to the expense of computing the child nodes.
Because of the size of the tree, we are trying to use
the large model for performance, but this causes the problem.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. compile test program
2. run test program
3. expand node c
4. expand node b
5. collapse node b
6. expand node b again
Node b "disappears" and node c takes its place.
Node b is really being drawn behind node c.
EXPECTED VERSUS ACTUAL BEHAVIOR :
I expected to be able to expand and collapse the nodes
at will with the correct display. But node b "disappears"
when it is repeatedly expanded and collapsed with node c
expanded.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import java.awt.*;
import java.awt.event.*;
public class TT
{
public static void main(String P_params[])
{
JFrame frame = new JFrame();
frame.addWindowListener (new WindowAdapter()
{
public void windowClosing(WindowEvent e) { System.exit(0); }
});
frame.getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT, 40,
40));
final JTree t = new JTree();
// Have to set this or setLargeModel(true) doesn't do anything.
t.setRowHeight(20);
// Removing setLargeModel(true) makes problem go away.
t.setLargeModel(true);
t.setPreferredSize(new Dimension(100, 200));
t.setRootVisible(false);
t.setShowsRootHandles(true);
DefaultMutableTreeNode root = new DefaultMutableTreeNode("");
DefaultMutableTreeNode a = new DefaultMutableTreeNode("a");
DefaultMutableTreeNode b = new DefaultMutableTreeNode("b");
DefaultMutableTreeNode c = new DefaultMutableTreeNode("c");
root.add(a);
root.add(b);
root.add(c);
b.add(new DefaultMutableTreeNode("b1"));
c.add(new DefaultMutableTreeNode("c2"));
t.setModel(new DefaultTreeModel(root));
frame.getContentPane().add(t);
t.addTreeExpansionListener(new TreeExpansionListener()
{
public void treeExpanded(TreeExpansionEvent e)
{
TreePath path = e.getPath();
if (path != null)
{
DefaultMutableTreeNode node =
(DefaultMutableTreeNode)path.getLastPathComponent();
System.out.println("expand " + node);
node.removeAllChildren();
// With this call, the node never expands!
//((DefaultTreeModel)t.getModel()).nodeStructureChanged(node);
node.add(new DefaultMutableTreeNode("1"));
node.add(new DefaultMutableTreeNode("2"));
node.add(new DefaultMutableTreeNode("3"));
node.add(new DefaultMutableTreeNode("4"));
node.add(new DefaultMutableTreeNode("5"));
node.add(new DefaultMutableTreeNode("6"));
//((DefaultTreeModel)t.getModel()).reload(node);
((DefaultTreeModel)t.getModel()).nodeStructureChanged(node);
}
}
public void treeCollapsed(TreeExpansionEvent e)
{
TreePath path = e.getPath();
if (path != null)
{
DefaultMutableTreeNode node =
(DefaultMutableTreeNode)path.getLastPathComponent();
System.out.println("collapse " + node);
}
}
});
frame.pack();
frame.setVisible(true);
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
I can leave largeModel set to false, but I want the
better performance promised by largeModel.
I think 4346229 & 4351323 are related,
but I don't understand the work-around given there.
I want to put a dummy child node under a parent to get
the right icon, then when the parent is expanded I will
remove the dummy node and replace it with the actual
child nodes.
(Review ID: 164042)
======================================================================
- duplicates
-
JDK-4745001 JTree with setLargeModel(true) not display correctly when expand/collapse nodes
-
- Resolved
-