Is it possible to customize a JTree Node?

506 views Asked by At

I want to try to implement a tree like this: Each node of the tree is a self defined component,which is composed of a JComboBox and a JTextField. Each time I select an item in the JComboBox, this node will generate three new sub nodes as leaves.

Is it possible to do that? I have tried using the TreeCellRender, but it seems that it just paints the combobox and the textfield, but the combobox is not selectable.

1

There are 1 answers

0
Robin On BEST ANSWER

What you want to do is editing the JTree. For this a renderer is not sufficient. Renderers are only used to 'render' the JTree, so are only sufficient if you have a read-only JTree.

If you want to edit the model behind the JTree as well, you have to set an editor on it.

The reason that your combobox is not selectable is explained in the Swing table tutorial, in the part about renderers and editors. The same applies for trees (but that tutorial does not contain such a section).