jide-oss
jide-oss copied to clipboard
CheckBoxTree ClassCastException after setModel()
We use a customized treemodel that implements TreeModel
that does not work with TreeNode
objects.
If we used the TreeModel constructor, everthing works fine:
cbtMain = new CheckBoxTree(new PositionenTreeModel(angebot, AngebotPosition.all(angebot)));
But if we used the empty constructor with following setModel(), a ClassCastException is thrown:
cbtMain = new CheckBoxTree();
cbtMain.setModel(new PositionenTreeModel(angebot, AngebotPosition.all(angebot)));
Exception in thread "main" java.lang.ClassCastException: de.rekers.ft._incubator.Angebot cannot be cast to javax.swing.tree.TreeNode
at javax.swing.tree.DefaultTreeModel.getChildCount(DefaultTreeModel.java:186)
at com.jidesoft.swing.CheckBoxTreeSelectionModel.getChildrenCount(CheckBoxTreeSelectionModel.java:557)
at com.jidesoft.swing.CheckBoxTreeSelectionModel.isPathSelected(CheckBoxTreeSelectionModel.java:169)
at com.jidesoft.swing.CheckBoxTreeCellRenderer.updateCheckBoxState(CheckBoxTreeCellRenderer.java:139)
at com.jidesoft.swing.CheckBoxTreeCellRenderer.getTreeCellRendererComponent(CheckBoxTreeCellRenderer.java:99)
at javax.swing.plaf.basic.BasicTreeUI$NodeDimensionsHandler.getNodeDimensions(BasicTreeUI.java:2807)
at javax.swing.tree.AbstractLayoutCache.getNodeDimensions(AbstractLayoutCache.java:492)
at javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.updatePreferredSize(VariableHeightLayoutCache.java:1360)
at javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.expand(VariableHeightLayoutCache.java:1473)
at javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.expand(VariableHeightLayoutCache.java:1288)
at javax.swing.tree.VariableHeightLayoutCache.rebuild(VariableHeightLayoutCache.java:743)
at javax.swing.tree.VariableHeightLayoutCache.setModel(VariableHeightLayoutCache.java:109)
at javax.swing.plaf.basic.BasicTreeUI.setModel(BasicTreeUI.java:412)
at javax.swing.plaf.basic.BasicTreeUI$Handler.propertyChange(BasicTreeUI.java:3414)
at java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:335)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:327)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:263)
at java.awt.Component.firePropertyChange(Component.java:8428)
at javax.swing.JTree.setModel(JTree.java:882)
at de.rekers.ft.app.angebotsverwaltung.AngebotPositionAuswahl.initUI(AngebotPositionAuswahl.java:50)
If 'rootVisible()' is set to false, no exception is thrown.
Our treemodel is not using 'DefaultTreeModel' but 'de.rekers.ft._incubator.Angebot'. It seems, that the old model from the empty constructor is accessing nodes from the new model.
Since we use a GUI-Designer, we need to use the standard constructor and set the model with setModel()
.