急求,JTree修改节点问题 20
publicvoideditingStopped(ChangeEvente){Objectobj=e.getSource();System.out.println(obj...
public void editingStopped(ChangeEvent e) {
Object obj = e.getSource();
System.out.println(obj.getClass().getName());
DefaultTreeCellEditor dtce = (DefaultTreeCellEditor) obj;
}
当对修改完成后,执行上面的事件后出现下面的错误提示:
System.out.println(obj.getClass().getName());语句输出的结果为:javax.swing.tree.DefaultTreeCellEditor$1
但在执行DefaultTreeCellEditor dtce = (DefaultTreeCellEditor) obj;语句时出现下面的错误
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.tree.DefaultTreeCellEditor$1 cannot be cast to javax.swing.tree.DefaultTreeCellEditor
at com.shuem.util.SimpleTree$CellEditorAction.editingStopped(SimpleTree.java:99)
at javax.swing.AbstractCellEditor.fireEditingStopped(AbstractCellEditor.java:125)
at javax.swing.DefaultCellEditor$EditorDelegate.stopCellEditing(DefaultCellEditor.java:350)
at javax.swing.DefaultCellEditor.stopCellEditing(DefaultCellEditor.java:215)
at javax.swing.DefaultCellEditor$EditorDelegate.actionPerformed(DefaultCellEditor.java:367)
at javax.swing.JTextField.fireActionPerformed(JTextField.java:492)
at javax.swing.JTextField.postActionEvent(JTextField.java:705)
at javax.swing.JTextField$NotifyAction.actionPerformed(JTextField.java:820)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1636)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2849)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2884)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2812)
at java.awt.Component.processEvent(Component.java:5911)
at java.awt.Container.processEvent(Container.java:2023)
at java.awt.Component.dispatchEventImpl(Component.java:4501)
at java.awt.Container.dispatchEventImpl(Container.java:2081)
at java.awt.Component.dispatchEvent(Component.java:4331)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1848)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:704)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:969)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:841)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:668)
at java.awt.Component.dispatchEventImpl(Component.java:4373)
at java.awt.Container.dispatchEventImpl(Container.java:2081)
at java.awt.Window.dispatchEventImpl(Window.java:2458)
at java.awt.Component.dispatchEvent(Component.java:4331)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) 展开
Object obj = e.getSource();
System.out.println(obj.getClass().getName());
DefaultTreeCellEditor dtce = (DefaultTreeCellEditor) obj;
}
当对修改完成后,执行上面的事件后出现下面的错误提示:
System.out.println(obj.getClass().getName());语句输出的结果为:javax.swing.tree.DefaultTreeCellEditor$1
但在执行DefaultTreeCellEditor dtce = (DefaultTreeCellEditor) obj;语句时出现下面的错误
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.tree.DefaultTreeCellEditor$1 cannot be cast to javax.swing.tree.DefaultTreeCellEditor
at com.shuem.util.SimpleTree$CellEditorAction.editingStopped(SimpleTree.java:99)
at javax.swing.AbstractCellEditor.fireEditingStopped(AbstractCellEditor.java:125)
at javax.swing.DefaultCellEditor$EditorDelegate.stopCellEditing(DefaultCellEditor.java:350)
at javax.swing.DefaultCellEditor.stopCellEditing(DefaultCellEditor.java:215)
at javax.swing.DefaultCellEditor$EditorDelegate.actionPerformed(DefaultCellEditor.java:367)
at javax.swing.JTextField.fireActionPerformed(JTextField.java:492)
at javax.swing.JTextField.postActionEvent(JTextField.java:705)
at javax.swing.JTextField$NotifyAction.actionPerformed(JTextField.java:820)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1636)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2849)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2884)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2812)
at java.awt.Component.processEvent(Component.java:5911)
at java.awt.Container.processEvent(Container.java:2023)
at java.awt.Component.dispatchEventImpl(Component.java:4501)
at java.awt.Container.dispatchEventImpl(Container.java:2081)
at java.awt.Component.dispatchEvent(Component.java:4331)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1848)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:704)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:969)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:841)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:668)
at java.awt.Component.dispatchEventImpl(Component.java:4373)
at java.awt.Container.dispatchEventImpl(Container.java:2081)
at java.awt.Window.dispatchEventImpl(Window.java:2458)
at java.awt.Component.dispatchEvent(Component.java:4331)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) 展开
1个回答
2013-08-28
展开全部
javax.swing.tree.DefaultTreeCellEditor$1表示的是DefaultTreeCellEditor的内部匿名类,因此它没有名字,那么我们可以通过e.getSource().getClass().getSuperClass()来知道它是实现了那个类或者是接口,那么就可以强制转换来实现相应的方法了
DefaultCellEditor dce = (DefaultCellEditor) e.getSource();
System.out.println(dce.getCellEditorValue());
帖子年代虽然久远,但是希望有类似问题的人,以后也可以这样类解决
DefaultCellEditor dce = (DefaultCellEditor) e.getSource();
System.out.println(dce.getCellEditorValue());
帖子年代虽然久远,但是希望有类似问题的人,以后也可以这样类解决
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询