これが問題です。DefaultMutableTreeNode を拡張する次のクラス FileNode があります
import javax.swing.tree.DefaultMutableTreeNode;
import java.io.File;
public class FileNode extends DefaultMutableTreeNode {
public FileNode(String Name, File File) {
super(Name);
this.Name = Name;
this.File = File;
this.isFolder = false;
CheckedOut = false;
}
public FileNode(String Name, File File, Boolean isFolder) {
super(Name);
this.Name = Name;
this.File = File;
this.isFolder = isFolder;
CheckedOut = false;
}
public Boolean CheckedOut;
public File File;
public String Name;
public Boolean isFolder;
}
これらのノードで満たされたツリーがあります。
次のキャスト例外が発生しています。
private class FileTreeCellRenderer 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);
FileNode fn = (FileNode)value;
Color nodeColor = Color.BLACK;
if (!fn.isFolder) {
if (fn.CheckedOut) {
nodeColor = Color.RED;
} else {
nodeColor = new Color(0,100,0);
}
}
setForeground(nodeColor);
return this;
}
}
奇妙なことに、Windows ではなく Linux でのみこのエラーが発生します。両方のプラットフォームで同じ JRE を実行しています - Oracle JDK 1.7.0_25
私が間違っていることについて誰か考えがありますか?
ここにスタックトレースがあります:
Exception in thread "main" java.lang.ClassCastException: javax.swing.tree.DefaultMutableTreeNode cannot be cast to dropboxcheckout.FileNode
at dropboxcheckout.CheckoutPanel$FileTreeCellRenderer.getTreeCellRendererComponent(CheckoutPanel.java:115)
at javax.swing.plaf.basic.BasicTreeUI$NodeDimensionsHandler.getNodeDimensions(BasicTreeUI.java:2786)
at javax.swing.tree.AbstractLayoutCache.getNodeDimensions(AbstractLayoutCache.java:492)
at javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.updatePreferredSize(VariableHeightLayoutCache.java:1359)
at javax.swing.tree.VariableHeightLayoutCache.updateNodeSizes(VariableHeightLayoutCache.java:917)
at javax.swing.tree.VariableHeightLayoutCache.invalidateSizes(VariableHeightLayoutCache.java:371)
at javax.swing.plaf.basic.BasicTreeUI.setCellRenderer(BasicTreeUI.java:385)
at javax.swing.plaf.basic.BasicTreeUI$Handler.propertyChange(BasicTreeUI.java:3390)
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:8382)
at javax.swing.JTree.setCellRenderer(JTree.java:759)
at dropboxcheckout.CheckoutPanel.<init>(CheckoutPanel.java:85)
at dropboxcheckout.CheckoutFrame.<init>(CheckoutFrame.java:37)