P
Polo488
Gast
Hallo
ich habe mir folgendes Beispiel angeschaut
How to Use Trees (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
Und folgende Klasse entwickelt
was ist mein Fehler? Exception
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: ApplicationFrame$1 cannot be cast to CustomTreeItem
at MyRenderer.getTreeCellRendererComponent(MyRenderer.java:24)
at javax.swing.plaf.basic.BasicTreeUI$NodeDimensionsHandler.getNodeDimensions(Unknown Source)
at javax.swing.tree.AbstractLayoutCache.getNodeDimensions(Unknown Source)
at javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.updatePreferredSize(Unknown Source)
at javax.swing.tree.VariableHeightLayoutCache.updateNodeSizes(Unknown Source)
at javax.swing.tree.VariableHeightLayoutCache.invalidateSizes(Unknown Source)
at javax.swing.plaf.basic.BasicTreeUI.setCellRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTreeUI$Handler.propertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.awt.Component.firePropertyChange(Unknown Source)
at javax.swing.JTree.setCellRenderer(Unknown Source)
at ApplicationFrame.initialize(ApplicationFrame.java:98)
at ApplicationFrame.<init>(ApplicationFrame.java:42)
at Application.StartApplicationFrame(Application.java:44)
at LoginDialog$2.actionPerformed(LoginDialog.java:169)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicRootPaneUI$Actions.actionPerformed(Unknown Source)
at javax.swing.SwingUtilities.notifyAction(Unknown Source)
at javax.swing.JComponent.processKeyBinding(Unknown Source)
at javax.swing.KeyboardManager.fireBinding(Unknown Source)
at javax.swing.KeyboardManager.fireKeyboardAction(Unknown Source)
at javax.swing.JComponent.processKeyBindingsForAllComponents(Unknown Source)
at javax.swing.JComponent.processKeyBindings(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
ich habe mir folgendes Beispiel angeschaut
How to Use Trees (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
Und folgende Klasse entwickelt
Java:
import java.awt.Component;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;
// Für die TreeIcons
public class MyRenderer extends DefaultTreeCellRenderer {
Icon DataBaseIcon;
Icon TableIcon;
Icon FieldIcon;
public MyRenderer(){
//DataBaseIcon = new ImageIcon("Icon/database-icon.png");
//TableIcon = new ImageIcon("Icon/Windows-Table-icon.png");
//FieldIcon = new ImageIcon("Icon/default-document-icon.png");
}
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);
CustomTreeItem Item =(CustomTreeItem)value;
if(Item.getHierachie()== Global.TreeHierachie.DataBase){
//setIcon(DataBaseIcon);
}
if(Item.getHierachie()== Global.TreeHierachie.Table){
//setIcon(TableIcon);
}
if(Item.getHierachie()== Global.TreeHierachie.Field){
//setIcon(FieldIcon);
}
return this;
}
}
was ist mein Fehler? Exception
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: ApplicationFrame$1 cannot be cast to CustomTreeItem
at MyRenderer.getTreeCellRendererComponent(MyRenderer.java:24)
at javax.swing.plaf.basic.BasicTreeUI$NodeDimensionsHandler.getNodeDimensions(Unknown Source)
at javax.swing.tree.AbstractLayoutCache.getNodeDimensions(Unknown Source)
at javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.updatePreferredSize(Unknown Source)
at javax.swing.tree.VariableHeightLayoutCache.updateNodeSizes(Unknown Source)
at javax.swing.tree.VariableHeightLayoutCache.invalidateSizes(Unknown Source)
at javax.swing.plaf.basic.BasicTreeUI.setCellRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTreeUI$Handler.propertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.awt.Component.firePropertyChange(Unknown Source)
at javax.swing.JTree.setCellRenderer(Unknown Source)
at ApplicationFrame.initialize(ApplicationFrame.java:98)
at ApplicationFrame.<init>(ApplicationFrame.java:42)
at Application.StartApplicationFrame(Application.java:44)
at LoginDialog$2.actionPerformed(LoginDialog.java:169)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicRootPaneUI$Actions.actionPerformed(Unknown Source)
at javax.swing.SwingUtilities.notifyAction(Unknown Source)
at javax.swing.JComponent.processKeyBinding(Unknown Source)
at javax.swing.KeyboardManager.fireBinding(Unknown Source)
at javax.swing.KeyboardManager.fireKeyboardAction(Unknown Source)
at javax.swing.JComponent.processKeyBindingsForAllComponents(Unknown Source)
at javax.swing.JComponent.processKeyBindings(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)