Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2007

Tip: Looking for answers? Try searching our database.

TreeCellEditor and TreeCellRenderer

Thread view: 
Jason Cavett - 06 Jul 2007 17:47 GMT
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.
volkanagun - 10 Jul 2007 22:25 GMT
> I'm a little confused about the differences between a CellEditor and a
> CellRenderer (specifically the "Tree" version).  From my
[quoted text clipped - 18 lines]
>
> 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.
Roedy Green - 12 Jul 2007 04:10 GMT
On Fri, 06 Jul 2007 09:47:01 -0700, Jason Cavett
<jason.cavett@gmail.com> wrote, quoted or indirectly quoted someone
who said :

>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?

Have a look at the code for TreeCellRenderer.  It is an interface with
only one method. It returns a Component -- in other words a rendered
cell.  Normally you recycle the same component over and over.

It has a simple job, something that looks like the cell, often just
selecting from a set of icons for leafs and nodes.

A TreeCellEditor is looks superficially to be identical.  It too
produces a component to represent that node/leaf.  However, that
component has to be smart enough to ALSO accept editing -- e.g.
keystrokes, an on-off switch, a JComboBox etc.

It would typically notify of changes by the attached
CellEditorListeners.

TreeCellRenderers get passed a hasFocus parameter , SO SOMEHOW the
JTree is tracking focus on a cell basis.

--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.