f



xml file in JTree: hide text nodes with only one character

Hello,
I am working on an app that will display an xml file in a JTree. So
far, element and text nodes are both correctly recognized. In fact,
the recognition is too good. THe xml file contains some line feeds
which are interpreted as text nodes are consequently displayed in the
tree as well. I tried to hide these node by using the following tree
cell renderer:
class XmlTreeCellRenderer extends JLabel implements TreeCellRenderer
{public Component getTreeCellRendererComponent
	(JTree tree, Object node, boolean selected, boolean expanded,
	boolean isLeaf, int row, boolean hasFocus)
{//* node is element node
if (((Node)node).getNodeType() == 1)
{this.setIcon(UIManager.getIcon("Tree.openIcon"));
this.setText(((Node)node).getNodeName());}
//* node is text node
if (((Node)node).getNodeType() == 3)
{if (((Node)node).getNodeValue().length() < 1)
{this.setVisible(false);}
this.setIcon(UIManager.getIcon("Tree.leafIcon"));
this.setText(((Node)node).getNodeValue());}
return this;}}
I had hoped that this code would make the text nodes with only one
character invisible. However, there was no change in display. I know
that the length of the text in the node is correctly determined.
Does anybody know what is wrong here?
Thanks
Peter
0
pit
6/18/2004 10:32:38 PM
comp.lang.java.gui 8286 articles. 0 followers. Post Follow

2 Replies
794 Views

Similar Articles

[PageSpeed] 30

> I am working on an app that will display an xml file in a JTree. So
> far, element and text nodes are both correctly recognized. In fact,
> the recognition is too good. THe xml file contains some line feeds
> which are interpreted as text nodes

this is the mistake - you should throw away such nodes, better - don't
recognize them as text nodes

-- 
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader


0
ak
6/19/2004 7:00:14 AM
"ak" <spam@imagero.com> wrote in message news:<cb0o8t$520$1@online.de>...
> > I am working on an app that will display an xml file in a JTree. So
> > far, element and text nodes are both correctly recognized. In fact,
> > the recognition is too good. THe xml file contains some line feeds
> > which are interpreted as text nodes
> 
> this is the mistake - you should throw away such nodes, better - don't
> recognize them as text nodes.
Hi ak,
well, that is what I would really like to do, but that would mean to
manually edit the files to remove the unneccesary line feeds and
spaces. Since most of the files I will have to deal with are created
manually or are supposed to be checked by human eyes, these
whitespaces are neccesary to make the file write- and readable. So
simply removing the "text nodes" is not an option.
Is there really no command to hide a JLabel?
Regard
Peter
0
pit
6/19/2004 1:43:58 PM
Reply: