-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
5.0
-
x86
-
windows_xp
Name: js151677 Date: 09/07/2004
FULL PRODUCT VERSION :
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Windows XP Pro SP1
A DESCRIPTION OF THE PROBLEM :
A ClassCastException is caused when a DefaultTreeCellRenderer child class tries to cast the value parameter in the getTreeCellRendererComponent() method to a DefaultMutableTreeNode child class _IF_ the Look and Feel is not set to the system default (Windows, unsure of other platforms).
It does also depend on the order that the setCellRenderer() and setModel() methods were called. If the setCellRenderer() is called before the setModel() and the Look and Feel is not set to the system default then an exception is caused whilst casting down.
also see
http://forum.java.sun.com/thread.jsp?forum=57&thread=120934
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
3 classes, just compile and run. Source code supplied below.
Try the combination of check boxes to see the behaviour. The faulty case is shown in the checkbox texts in parantesis . (ANY / OFF / ON in order)
Note the System.out output in the faulty case either says
javax.swing.tree.DefaultMutableTreeNode JTree
or
javax.swing.tree.DefaultMutableTreeNode colors
depending on if the root node is visible / hidden
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
it should not matter the order that
tree.setCellRenderer(new BugTreeCellRenderer());
tree.setModel(model);
lines are executed and it should also not depend on the current LAF
Since the TreeModel was constructed using only the BugTreeNode objects (including the root node) then all the nodes given to the getTreeCellRendererComponent() should also all be BugTreeNode.
ACTUAL -
If the LAF is not System Default and setCellRenderer() is done before the setModel() an exception occures since no model has yet been set.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
2 exceptions :
Only difference between the two is if the root node was visible and the toString() value of the value parameter as can bee seen on the fifth line of each (The line begining with javax.swing.tree.DefaultMutableTreeNode)
Note that the type of node given in the value parameter is javax.swing.tree.DefaultMutableTreeNode and not BugTreeNode
# Start #############################################
Root : Visible
Order : setCellRenderer / SetModel
LAF : Ocean
javax.swing.tree.DefaultMutableTreeNode JTree
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.tree.DefaultMutableTreeNode
at BugTreeCellRenderer.getTreeCellRendererComponent(BugTreeCellRenderer.java:27)
at javax.swing.plaf.basic.BasicTreeUI$NodeDimensionsHandler.getNodeDimensions(BasicTreeUI.java:2637)
at javax.swing.tree.AbstractLayoutCache.getNodeDimensions(AbstractLayoutCache.java:475)
at javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.updatePreferredSize(VariableHeightLayoutCache.java:1342)
at javax.swing.tree.VariableHeightLayoutCache.updateNodeSizes(VariableHeightLayoutCache.java:900)
at javax.swing.tree.VariableHeightLayoutCache.invalidateSizes(VariableHeightLayoutCache.java:354)
at javax.swing.plaf.basic.BasicTreeUI.setCellRenderer(BasicTreeUI.java:364)
at javax.swing.plaf.basic.BasicTreeUI$Handler.propertyChange(BasicTreeUI.java:3306)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:270)
at java.awt.Component.firePropertyChange(Component.java:7122)
at javax.swing.JTree.setCellRenderer(JTree.java:595)
at BugTreeDemo.showTree(BugTreeDemo.java:79)
at BugTreeDemo.access$100(BugTreeDemo.java:6)
at BugTreeDemo$2.actionPerformed(BugTreeDemo.java:52)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2167)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5465)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3089)
at java.awt.Component.processEvent(Component.java:5230)
at java.awt.Container.processEvent(Container.java:1961)
at java.awt.Component.dispatchEventImpl(Component.java:3933)
at java.awt.Container.dispatchEventImpl(Container.java:2019)
at java.awt.Component.dispatchEvent(Component.java:3781)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4205)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3885)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3815)
at java.awt.Container.dispatchEventImpl(Container.java:2005)
at java.awt.Window.dispatchEventImpl(Window.java:1764)
at java.awt.Component.dispatchEvent(Component.java:3781)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
# Start #############################################
Root : Hidden
Order : setCellRenderer / SetModel
LAF : Ocean
javax.swing.tree.DefaultMutableTreeNode colors
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.tree.DefaultMutableTreeNode
at BugTreeCellRenderer.getTreeCellRendererComponent(BugTreeCellRenderer.java:27)
at javax.swing.plaf.basic.BasicTreeUI$NodeDimensionsHandler.getNodeDimensions(BasicTreeUI.java:2637)
at javax.swing.tree.AbstractLayoutCache.getNodeDimensions(AbstractLayoutCache.java:475)
at javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.updatePreferredSize(VariableHeightLayoutCache.java:1342)
at javax.swing.tree.VariableHeightLayoutCache.updateNodeSizes(VariableHeightLayoutCache.java:900)
at javax.swing.tree.VariableHeightLayoutCache.invalidateSizes(VariableHeightLayoutCache.java:354)
at javax.swing.plaf.basic.BasicTreeUI.setCellRenderer(BasicTreeUI.java:364)
at javax.swing.plaf.basic.BasicTreeUI$Handler.propertyChange(BasicTreeUI.java:3306)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:270)
at java.awt.Component.firePropertyChange(Component.java:7122)
at javax.swing.JTree.setCellRenderer(JTree.java:595)
at BugTreeDemo.showTree(BugTreeDemo.java:79)
at BugTreeDemo.access$100(BugTreeDemo.java:6)
at BugTreeDemo$2.actionPerformed(BugTreeDemo.java:52)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2167)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5465)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3089)
at java.awt.Component.processEvent(Component.java:5230)
at java.awt.Container.processEvent(Container.java:1961)
at java.awt.Component.dispatchEventImpl(Component.java:3933)
at java.awt.Container.dispatchEventImpl(Container.java:2019)
at java.awt.Component.dispatchEvent(Component.java:3781)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4205)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3885)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3815)
at java.awt.Container.dispatchEventImpl(Container.java:2005)
at java.awt.Window.dispatchEventImpl(Window.java:1764)
at java.awt.Component.dispatchEvent(Component.java:3781)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import javax.swing.tree.*;
public class BugTreeNode
extends DefaultMutableTreeNode
{
public BugTreeNode(Object userObject)
{
super(userObject);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import javax.swing.tree.*;
import java.awt.*;
import javax.swing.*;
public class BugTreeCellRenderer
extends DefaultTreeCellRenderer
{
public Component getTreeCellRendererComponent(JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus)
{
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
System.out.println(value.getClass().getName() + "\t\t" + value.toString());
// WORKAROUND
// if (!(value instanceof BugTreeNode))
// {
// return this;
// }
BugTreeNode n = (BugTreeNode) value;
// do something based on the value and the node type
return this;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
public class BugTreeDemo
extends JFrame
{
private JCheckBox bLAF;
private JCheckBox bOrder;
private JCheckBox bVisible;
public static void main(String[] args)
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception ex)
{
}
new BugTreeDemo();
}
public BugTreeDemo()
{
super("BugTreeDemo");
bVisible = new JCheckBox("Root Node is visible (ANY)", true);
bOrder = new JCheckBox("SetModel() before setCellRenderer() (OFF)", true);
bLAF = new JCheckBox("Ocean Look and Feel (ON)", false);
bLAF.addActionListener(new ActionListener()
{ public void actionPerformed(ActionEvent e)
{ try
{
if (BugTreeDemo.this.bLAF.isSelected())
{
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
else
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
SwingUtilities.updateComponentTreeUI(BugTreeDemo.this.getContentPane());
}
catch (Exception ex)
{
}
} } );
JButton bTree = new JButton("Show Tree");
bTree.addActionListener(new ActionListener()
{ public void actionPerformed(ActionEvent e)
{ BugTreeDemo.this.showTree();
} } );
add(bVisible);
add(bOrder);
add(bLAF);
add(bTree);
setLayout(new GridLayout(0, 1));
setSize(300, 100);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
private void showTree()
{
System.out.println("# Start #############################################");
System.out.println("Root : " + (bVisible.isSelected() ? "Visible" : "Hidden"));
System.out.println("Order : " + (bOrder .isSelected() ? "setCellRenderer / SetModel" : "SetModel / setCellRenderer"));
System.out.println("LAF : " + (bLAF .isSelected() ? "Ocean" : "System"));
JDialog dialog = new JDialog(this);
dialog.setSize(100, 200);
dialog.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
JTree tree = new JTree();
tree.setRootVisible(bVisible.isSelected());
TreeModel model = getTreeModel();
if (bOrder.isSelected())
{
tree.setModel(model);
tree.setCellRenderer(new BugTreeCellRenderer());
}
else
{
tree.setCellRenderer(new BugTreeCellRenderer());
tree.setModel(model);
}
dialog.add(new JScrollPane(tree));
System.out.println("# End ###############################################");
dialog.setVisible(true);
}
private TreeModel getTreeModel()
{
BugTreeNode root = new BugTreeNode("ROOT");
root.add(new BugTreeNode("CHILD"));
TreeModel model = new DefaultTreeModel(root);
return model;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The commented lines in BugTreeCellRenderer if uncommented prevent the problem
// WORKAROUND
// if (!(value instanceof BugTreeNode))
// {
// return this;
// }
(Incident Review ID: 302116)
======================================================================
FULL PRODUCT VERSION :
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Windows XP Pro SP1
A DESCRIPTION OF THE PROBLEM :
A ClassCastException is caused when a DefaultTreeCellRenderer child class tries to cast the value parameter in the getTreeCellRendererComponent() method to a DefaultMutableTreeNode child class _IF_ the Look and Feel is not set to the system default (Windows, unsure of other platforms).
It does also depend on the order that the setCellRenderer() and setModel() methods were called. If the setCellRenderer() is called before the setModel() and the Look and Feel is not set to the system default then an exception is caused whilst casting down.
also see
http://forum.java.sun.com/thread.jsp?forum=57&thread=120934
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
3 classes, just compile and run. Source code supplied below.
Try the combination of check boxes to see the behaviour. The faulty case is shown in the checkbox texts in parantesis . (ANY / OFF / ON in order)
Note the System.out output in the faulty case either says
javax.swing.tree.DefaultMutableTreeNode JTree
or
javax.swing.tree.DefaultMutableTreeNode colors
depending on if the root node is visible / hidden
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
it should not matter the order that
tree.setCellRenderer(new BugTreeCellRenderer());
tree.setModel(model);
lines are executed and it should also not depend on the current LAF
Since the TreeModel was constructed using only the BugTreeNode objects (including the root node) then all the nodes given to the getTreeCellRendererComponent() should also all be BugTreeNode.
ACTUAL -
If the LAF is not System Default and setCellRenderer() is done before the setModel() an exception occures since no model has yet been set.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
2 exceptions :
Only difference between the two is if the root node was visible and the toString() value of the value parameter as can bee seen on the fifth line of each (The line begining with javax.swing.tree.DefaultMutableTreeNode)
Note that the type of node given in the value parameter is javax.swing.tree.DefaultMutableTreeNode and not BugTreeNode
# Start #############################################
Root : Visible
Order : setCellRenderer / SetModel
LAF : Ocean
javax.swing.tree.DefaultMutableTreeNode JTree
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.tree.DefaultMutableTreeNode
at BugTreeCellRenderer.getTreeCellRendererComponent(BugTreeCellRenderer.java:27)
at javax.swing.plaf.basic.BasicTreeUI$NodeDimensionsHandler.getNodeDimensions(BasicTreeUI.java:2637)
at javax.swing.tree.AbstractLayoutCache.getNodeDimensions(AbstractLayoutCache.java:475)
at javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.updatePreferredSize(VariableHeightLayoutCache.java:1342)
at javax.swing.tree.VariableHeightLayoutCache.updateNodeSizes(VariableHeightLayoutCache.java:900)
at javax.swing.tree.VariableHeightLayoutCache.invalidateSizes(VariableHeightLayoutCache.java:354)
at javax.swing.plaf.basic.BasicTreeUI.setCellRenderer(BasicTreeUI.java:364)
at javax.swing.plaf.basic.BasicTreeUI$Handler.propertyChange(BasicTreeUI.java:3306)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:270)
at java.awt.Component.firePropertyChange(Component.java:7122)
at javax.swing.JTree.setCellRenderer(JTree.java:595)
at BugTreeDemo.showTree(BugTreeDemo.java:79)
at BugTreeDemo.access$100(BugTreeDemo.java:6)
at BugTreeDemo$2.actionPerformed(BugTreeDemo.java:52)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2167)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5465)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3089)
at java.awt.Component.processEvent(Component.java:5230)
at java.awt.Container.processEvent(Container.java:1961)
at java.awt.Component.dispatchEventImpl(Component.java:3933)
at java.awt.Container.dispatchEventImpl(Container.java:2019)
at java.awt.Component.dispatchEvent(Component.java:3781)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4205)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3885)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3815)
at java.awt.Container.dispatchEventImpl(Container.java:2005)
at java.awt.Window.dispatchEventImpl(Window.java:1764)
at java.awt.Component.dispatchEvent(Component.java:3781)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
# Start #############################################
Root : Hidden
Order : setCellRenderer / SetModel
LAF : Ocean
javax.swing.tree.DefaultMutableTreeNode colors
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.tree.DefaultMutableTreeNode
at BugTreeCellRenderer.getTreeCellRendererComponent(BugTreeCellRenderer.java:27)
at javax.swing.plaf.basic.BasicTreeUI$NodeDimensionsHandler.getNodeDimensions(BasicTreeUI.java:2637)
at javax.swing.tree.AbstractLayoutCache.getNodeDimensions(AbstractLayoutCache.java:475)
at javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.updatePreferredSize(VariableHeightLayoutCache.java:1342)
at javax.swing.tree.VariableHeightLayoutCache.updateNodeSizes(VariableHeightLayoutCache.java:900)
at javax.swing.tree.VariableHeightLayoutCache.invalidateSizes(VariableHeightLayoutCache.java:354)
at javax.swing.plaf.basic.BasicTreeUI.setCellRenderer(BasicTreeUI.java:364)
at javax.swing.plaf.basic.BasicTreeUI$Handler.propertyChange(BasicTreeUI.java:3306)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:270)
at java.awt.Component.firePropertyChange(Component.java:7122)
at javax.swing.JTree.setCellRenderer(JTree.java:595)
at BugTreeDemo.showTree(BugTreeDemo.java:79)
at BugTreeDemo.access$100(BugTreeDemo.java:6)
at BugTreeDemo$2.actionPerformed(BugTreeDemo.java:52)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2167)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5465)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3089)
at java.awt.Component.processEvent(Component.java:5230)
at java.awt.Container.processEvent(Container.java:1961)
at java.awt.Component.dispatchEventImpl(Component.java:3933)
at java.awt.Container.dispatchEventImpl(Container.java:2019)
at java.awt.Component.dispatchEvent(Component.java:3781)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4205)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3885)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3815)
at java.awt.Container.dispatchEventImpl(Container.java:2005)
at java.awt.Window.dispatchEventImpl(Window.java:1764)
at java.awt.Component.dispatchEvent(Component.java:3781)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import javax.swing.tree.*;
public class BugTreeNode
extends DefaultMutableTreeNode
{
public BugTreeNode(Object userObject)
{
super(userObject);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import javax.swing.tree.*;
import java.awt.*;
import javax.swing.*;
public class BugTreeCellRenderer
extends DefaultTreeCellRenderer
{
public Component getTreeCellRendererComponent(JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus)
{
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
System.out.println(value.getClass().getName() + "\t\t" + value.toString());
// WORKAROUND
// if (!(value instanceof BugTreeNode))
// {
// return this;
// }
BugTreeNode n = (BugTreeNode) value;
// do something based on the value and the node type
return this;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
public class BugTreeDemo
extends JFrame
{
private JCheckBox bLAF;
private JCheckBox bOrder;
private JCheckBox bVisible;
public static void main(String[] args)
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception ex)
{
}
new BugTreeDemo();
}
public BugTreeDemo()
{
super("BugTreeDemo");
bVisible = new JCheckBox("Root Node is visible (ANY)", true);
bOrder = new JCheckBox("SetModel() before setCellRenderer() (OFF)", true);
bLAF = new JCheckBox("Ocean Look and Feel (ON)", false);
bLAF.addActionListener(new ActionListener()
{ public void actionPerformed(ActionEvent e)
{ try
{
if (BugTreeDemo.this.bLAF.isSelected())
{
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
else
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
SwingUtilities.updateComponentTreeUI(BugTreeDemo.this.getContentPane());
}
catch (Exception ex)
{
}
} } );
JButton bTree = new JButton("Show Tree");
bTree.addActionListener(new ActionListener()
{ public void actionPerformed(ActionEvent e)
{ BugTreeDemo.this.showTree();
} } );
add(bVisible);
add(bOrder);
add(bLAF);
add(bTree);
setLayout(new GridLayout(0, 1));
setSize(300, 100);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
private void showTree()
{
System.out.println("# Start #############################################");
System.out.println("Root : " + (bVisible.isSelected() ? "Visible" : "Hidden"));
System.out.println("Order : " + (bOrder .isSelected() ? "setCellRenderer / SetModel" : "SetModel / setCellRenderer"));
System.out.println("LAF : " + (bLAF .isSelected() ? "Ocean" : "System"));
JDialog dialog = new JDialog(this);
dialog.setSize(100, 200);
dialog.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
JTree tree = new JTree();
tree.setRootVisible(bVisible.isSelected());
TreeModel model = getTreeModel();
if (bOrder.isSelected())
{
tree.setModel(model);
tree.setCellRenderer(new BugTreeCellRenderer());
}
else
{
tree.setCellRenderer(new BugTreeCellRenderer());
tree.setModel(model);
}
dialog.add(new JScrollPane(tree));
System.out.println("# End ###############################################");
dialog.setVisible(true);
}
private TreeModel getTreeModel()
{
BugTreeNode root = new BugTreeNode("ROOT");
root.add(new BugTreeNode("CHILD"));
TreeModel model = new DefaultTreeModel(root);
return model;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The commented lines in BugTreeCellRenderer if uncommented prevent the problem
// WORKAROUND
// if (!(value instanceof BugTreeNode))
// {
// return this;
// }
(Incident Review ID: 302116)
======================================================================