Using JTable for a JTree cell editor

怎甘沉沦 提交于 2019-12-11 04:07:30

问题


I would like to use a JTable for editing a JTree, I extended DefaultTreeCellEditor and implemented isCellEditable getTreeCellEditorComponent, in getTreeCellEditorComponent I return a JTable. Everything works up to this point when a node is edited swing displays the JTable filled with the objects content however when editing is complete, valueForPathChanged of DefaultTreeModel never gets called. If I use a text field for editing which is the default everything works fine.


回答1:


JTextField has a notifyAction, named "notify-field-accept" and typically bound to KeyEvent.VK_ENTER, that signals the CellEditor to stopEditing() and ultimately invokes the DefaultTreeCellEditor method, valueForPathChanged().

It's not clear how you indicate that editing is complete for your JTable. You should be able to do something like JTextField in a CellEditorListener that is added to your custom editor via addCellEditorListener().

Incidentally, valueForPathChanged() mentions that "If you use custom user objects in the TreeModel you're going to need to subclass this and set the user object of the changed node to something meaningful."



来源:https://stackoverflow.com/questions/3432218/using-jtable-for-a-jtree-cell-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!