Re: TreeCellRenderer.setIcon(null) -> performance loss

From: Piet (pit.grinja_at_gmx.de)
Date: 06/22/04


Date: 21 Jun 2004 23:44:02 -0700

Hi Thomas,
> I really don't understand what is your issue here. If you don't want to
> have something displayed, don't let the model give it to the tree. The
> easiest way a model doesn't give a node to the tree is to let the model
> not have that node at all.
>
> So, why do you put something (the empty elements) in the tree, if you
> don't want to display them? If you never want to see them, they
> shouldn't have been put in the model at all. If you need the tree
> contents dynamically changing based on some preference, implement a
> filtering tree model as a wrapper around your real data.
Actually, I do not put anything in the tree, at least not explicitly.
I defined my tree model by implementing the TreeModel interface and
creating functions like getRoot, getChildren asf. by filling then with
Xml DOM commands that would return the information required by the
JTree. I was surprised to see that this simple approach really worked
and that I didnīt have to add anything explicitly to the tree. The
tree is basically build "automatically" when the XML document is
parsed. I then tried to modify the commands that e.g. return the
number of children but that was a big hassle and basically didnīt
bring me a step forward.
So what I was looking for was a mechanism that would allow me to make
some nodes "invisble" so that they would still be in the DOM but not
displayed in the JTree. One approach aling these lines was to create a
TreeCellRenderer that should hide the tree label by using the
"this.setVisible(false)" method, but that didnīt work.
However, your are not the first and only one who doesnīt get the
point. I think about a different approach by constructing the JTree
from simple DefaultTreeNodes and attaching the XML node object to the
DefaultTreeNode objects via get/setClientData and get a good Swing
book ASAP.

Regards
Peter



Relevant Pages

  • Re: TreeView Dynamic XML Binding
    ... Subject: TreeView Dynamic XML Binding ... Expand the ReturnHeader node. ... When I click on the tree node for the select ... I'm simply trying to display the xml element tree ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • [SWING] Problem with JTree
    ... I use a subclass of JTree that overwrites getCellRendererto get full control over the cell renders. ... If i try to display the structure and content of the object using my tree the tree is not displayed correctly. ... My TreeCellRenderer implementations are subclasses of DefaultTreeCellRenderer and overwrite getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) to determine the current value and call the super method. ... Additionally there's a TreeSelectionListener registered at the JTree that triggers the display of extra information on a separate JPanel. ...
    (comp.lang.java.programmer)
  • Re: JTree usage/archetecture
    ... node-dependant editor on the right. ... > need concern myself with (JTree, TreeModel, DefaultMutableTreeNode, ... > listining for a custom event on the editor then refressing the tree. ... I have been working on an XML ...
    (comp.lang.java.gui)
  • wxPython: wxGrid vs. wxListCtrl
    ... I am working on an XML editor that will not display the xml file as ... Building the tree view was not a problem, but I havenīt found a good ... because when the cell content changes I would like ...
    (comp.lang.python)
  • Re: TreeView Dynamic XML Binding
    ... Subject: TreeView Dynamic XML Binding ... Expand the ReturnHeader node. ... When I click on the tree node for the select ... I'm simply trying to display the xml element tree ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)