急求,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)
展开
 我来答
匿名用户
2013-08-28
展开全部
javax.swing.tree.DefaultTreeCellEditor$1表示的是DefaultTreeCellEditor的内部匿名类,因此它没有名字,那么我们可以通过e.getSource().getClass().getSuperClass()来知道它是实现了那个类或者是接口,那么就可以强制转换来实现相应的方法了
DefaultCellEditor dce = (DefaultCellEditor) e.getSource();
System.out.println(dce.getCellEditorValue());
帖子年代虽然久远,但是希望有类似问题的人,以后也可以这样类解决
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式