-
Bug
-
Resolution: Fixed
-
P3
-
1.2.0
-
1.2.2
-
sparc
-
solaris_2.5
Name: vsC58871 Date: 08/05/98
com.sun.java.swing.tree.DefaultTreeCellRenderer methods
getDefaultClosedIcon(), getDefaultOpenIcon() and getDefaultLeafIcon()
return wrong Icons.
Javadoc says:
/**
* Returns the default icon used to represent <snip> nodes.
*/
But these methods return current icons instead of the default ones.
Here is the code from DefaultTreeCellRenderer.java:
public Icon getDefaultOpenIcon() {
return openIcon;
}
public void setOpenIcon(Icon newIcon) {
openIcon = newIcon;
}
public Icon getOpenIcon() {
return openIcon;
}
So, getDefaultXXXIcon methods may return whichever icon set
by setXXXIcon() method.
But default icons should be determined from UIManager.
Here is the example demonstrating the bug:
----------------Test.java---------------------
import com.sun.java.swing.*;
import com.sun.java.swing.tree.*;
import java.awt.*;
public class Test {
public static void main(String[] args){
Icon defaultIcon, anotherIcon, resultIcon;
DefaultTreeCellRenderer r = new DefaultTreeCellRenderer();
defaultIcon = r.getDefaultOpenIcon(); //get icon from UIManager
anotherIcon = new Icon() {
public int getIconWidth() {
return 32;
}
public int getIconHeight() {
return 32;
}
public void paintIcon(Component c, Graphics g, int x, int y) {}
};
r.setOpenIcon(anotherIcon);
resultIcon = r.getDefaultOpenIcon();
if (!resultIcon.equals(defaultIcon)) {
System.out.println("Expected Default Icon: " + defaultIcon);
System.out.println("Returned Icon: " + resultIcon);
System.out.println("Test Failed.");
System.exit(0);
}
System.out.println("Test Passed.");
}
}
-- The output ----------------
#>java -version
java version "1.2fcs"
Classic VM (build JDK-1.2fcs-D, green threads, sunwjit)
#>java Test
Expected Default Icon:
com.sun.java.swing.plaf.metal.MetalIconFactory$TreeFolderIcon@a7ae36df
Returned Icon: Test$1@b96a36df
Test Failed.
------------------------------
======================================================================