0

I have a JXTreeTable for which data model extends DefaultTreeTableModel, and CustomNode extends AbstractMutableTreeTableNode. Each column is editable as expected, as well as hierarchical tree node.

How to apply custom editor (TreeTableCellEditor) to hierarchical column in JXTreeTable?

The following were several attempts, yet yielded not expected results:

treeTable.setCellEditor(editor) 
treeTable.getColumnModel().getColumn(0).setCellEditor(editor)
treeTable.getColumn(0).setCellEditor(editor)
treeTable.getColumnExt(0).setCellEditor(editor)

I was able to get the inherent tree used for rendering the hierarchical column, but also unable to specify custom editor through it.

private JTree getTree(JXTreeTable treeTable){
     try{
        Field field = JXTreeTable.class.getDeclaredField("renderer");
        field.setAccessible(true);
        return (JTree)field.get(treeTable);
     }catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex){
        throw new RuntimeException(ex);
     }
}

It seems that there were a "workaround" that was posted previsouly but I am not able to access to the page content: http://forums.java.net/jive/message.jspa?messageID=387603 (in https://java.net/projects/swingx/lists/issues/archive/2012-06/message/22)

Any clue to specify custom editor to tree column?

Thank you very much for your feedback.

will
  • 1
  • 1

1 Answers1

1

I have no reputation to comment, but thanks to WayBack Machine this is the "workaround" mentioned by "will": https://web.archive.org/web/20120831192839/http://www.java.net/node/701358

In any case (if this link is also removed) here is the "workaround" answer (as is), powered by kleopatra:


hmmm ... you are right: looks like we have no api to hook a custom editor. Would you please file an issue so we don't forget? Not that there would be a high probability to have it tackled any time soon, but who knows (volunteering anybody?)

Meanwhile, the only way I see is to subclass the treeTable and override getCellEditor, something like:

@override
public TableCellEditor getTableCellEditor(row, column) {
   if (isHierachicalColumn(column)) {
      return myTreeTableCellEditor;
   }
   return super....
}

The only way to get hold of the tree (it's a tightly protected family secret :) is dirty:

JXTree tree = (JXTree) treeTable.getCellRenderer(anyrow, getHierarchicalColumn());
MyTreeTableCellRenderer r = new MyTreeTableCellRenderer(tree);

arrgghhh ...

CU Jeanette


Now, I'll try if this works, at least to take any idea :)

LMSanchez
  • 11
  • 3