没有getCellEditorValue的TreeCellEditor

时间:2018-10-03 20:11:30

标签: java jtree

我正在使用JTree上的TreeCellEditor编辑多个节点。

我将所有选定的节点传递给集合中的编辑器。

  DeviceEditor deviceEditor = new DeviceEditor(nodes);
  itemTree.setCellEditor(deviceEditor);

我比较所有节点,并在编辑器窗体上列出存在多个值的“多个值”。

该表单具有一个更新按钮来触发JTree.stopCellEditing函数,如下所示:

    @Override
public boolean stopCellEditing() {
    try {
        DeviceEditor.UPDATE_DEVICES(nodes, multiValueDevice);
        return true;
    } catch (IPConverter.InvalidIPException ex) {
        Exceptions.printStackTrace(ex);
        return false;
    }

单元格编辑功能都可以正常工作,但是我遇到的问题是此处显示的JTree.stopEditing():

                    deviceEditor.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent ae) {
                        System.out.println("ACTION COMMAND= " + ae.getActionCommand());
                        if ("Update".equals(ae.getActionCommand())) {
                            //get the Device From the editor.
                            //update all the nodes' userObjects to the values of the editor except the ones with <Multiple Values>
                            //stopEditing expects an Object from DeviceEditor. We need a way to stopEditing without providing an object. 
                            itemTree.stopEditing(); //update the nodes

                        }
                        if ("Cancel".equals(ae.getActionCommand())) {
                            itemTree.cancelEditing();
                        }
                    }
                });

itemTree.stopEditing似乎从TreeCellEditor调用getCellEditorValue。由于我已经编辑了所有节点,因此在这里没有任何内容可提供。

在这里关闭编辑器需要做什么?

0 个答案:

没有答案