Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CheckBoxTree ClassCastException after setModel() #28

Open
mwithake opened this issue Mar 20, 2018 · 0 comments
Open

CheckBoxTree ClassCastException after setModel() #28

mwithake opened this issue Mar 20, 2018 · 0 comments

Comments

@mwithake
Copy link

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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant