-
Bug
-
Resolution: Fixed
-
P4
-
1.2.1
-
beta
-
sparc
-
solaris_2.5.1
Name: sdC67446 Date: 03/26/99
The method
public int getPreferredWidth(Rectangle bounds)
of class AbstractLayoutCache calculates width unfairly.
The method ignores the last path while running through the LIST of paths
and calculating the maximum width (where The LIST is the list of paths which
are in 'bounds' and visible, or just visible if 'bounds'==null).
The doc says:
--------------------------------------------------
public int getPreferredWidth(Rectangle bounds);
Returns the preferred width for the passed in region. If
bounds is null, the preferred width for all the nodes
will be returned (and this may be VERY expensive).
The test demonstrating the bug:
-----------------Test.java------------------------
import javax.swing.tree.*;
import javax.swing.event.*;
import java.awt.Rectangle;
public class Test extends FixedHeightLayoutCache {
public Test() {
super();
}
public DefaultTreeModel getTreeModelILike(int children) {
DefaultMutableTreeNode root =
new DefaultMutableTreeNode(new String("root"));
for (int i = 0; i < children; i++) {
DefaultMutableTreeNode child =
// {***} getBounds will return {1,2,3}
new DefaultMutableTreeNode(new Integer(i+1));
root.insert(child,i);
}
return new DefaultTreeModel(root);
}
public Rectangle getBounds(TreePath path, Rectangle bounds) {
DefaultMutableTreeNode node =
(DefaultMutableTreeNode)path.getLastPathComponent();
int width = ((Integer)((node).getUserObject())).intValue();
System.out.println("getBounds("+path+", ..)");
// {***}
return new Rectangle(0,0,width,0);
}
public static void main(String[] args) {
Test test = new Test();
test.setModel(test.getTreeModelILike(3));
int width = test.getPreferredWidth(null);
if (width == 3) {
System.out.println("It's Ok.");
} else {
System.out.println(width+" != 3");
}
}
}
---------Output from the test---------------------
getBounds([root, 1], ..)
getBounds([root, 2], ..)
getBounds([root, 3], ..)
2 != 3
--------------------------------------------------
======================================================================