Re: TreeCellEditor and TreeCellRenderer
On 6 Temmuz, 19:47, Jason Cavett <jason.cav...@gmail.com> wrote:
I'm a little confused about the differences between a CellEditor and a
CellRenderer (specifically the "Tree" version). From my
understanding, the renderer is HOW the icons are displayed and the
editor is how to edit the fields. It seems other people have this
same idea from my searches in Google.
If this is right, what I am confused about is why a
DefaultTreeCellEditor takes a DefaultTreeCellRenderer as part of its
constructor? Is this so icons can be rendered even when editing?
The reason I ask is I have created my own TreeCellEditor and my own
TreeCellRenderer by subclassing DefaultTreeCellEditor and
DefaultTreeCellRenderer, respectively. Within my renderer, I wrote
the logic so that the icons would be set to icons I wanted (based on
the current state of a node in the tree since I have different states
other than open/close). Within my editor I override
determineOffset(...) so that I can keep the current active Icon and
don't get the default folder/bullet icons. I also implement
CellEditorListener so I can tell when a person starts/stops editing
the tree node name.
Am I approaching this correctly? Thanks for any feedback.
Hi, I am also confused with the idea but I have an opinion,
Actually the renderer part only for display, it takes your specific
(BookInfo)class variables and displayes them where you want, this info
comes into the JTree at the construction. And the editor, is the
reverse operation, when you edit some thing it recognize and fires
some events, at this part it uses "public Object getCellEditorValue
()" in order to create new instances from your inputs for example;
public Object getCellEditorValue ()
{
JTextField textField = renderer.getRenderer ();
OntologyNode node = new OntologyNode (); //MY INFO
node.setValue (textField.getText ());
node.setValue (textField.getText ());
return node;
}
so that when your editing finished it calls this method.
I think you work only for icons, but there can be done anything with
the idea, you can displaye you usercontrols in JTree and also edit
them.