Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #2305

Re: JTree forcing node to

From "Rogan Dawes" <rogan.dawes@THRWHITE.remove-dii-this>
Subject Re: JTree forcing node to
Message-ID <a8udnX8_PJa3mFHbRVnyjQA@saix.net> (permalink)
Newsgroups comp.lang.java.gui
References <1187739706.626536.157780@x40g2000prg.googlegroups.com>
Date 2011-04-27 15:38 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
lionelv@gmail.com wrote:
> I've got a JTree and I've extended AbstractTreeNode creating 3
> different types of nodes. One of my subclasses is a Directory node. In
> JTree when a node has children it automatically sets the icon of that
> node to look something like a folder. However, if the node doesn't
> have children then it looks like a leaf node.
> 
> Is there a simple solution to force a node to have the directory icon?
> I assume I have to set the cell renderer, but I'm hoping I don't have
> to create the renderer myself.
> 
> thanks
> 
> Lionel.
> 

The other approach is to fix your tree model so that 
TreeModel.isLeaf(Object node) return true for your Directory nodes.

See 
<http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/tree/TreeModel.html#isLeaf(java.lang.Object)>

Either override the DefaultTreeModel (if that is what you are using), or 
implement your own custom TreeModel if it makes sense in your project 
(e.g. if you are actually mapping an existing data structure into a 
tree, such as a filesystem)

Regards,

Rogan

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

JTree forcing node to hav lionelv@gmail.com.remove-dii-this - 2011-04-27 15:38 +0000
  Re: JTree forcing node to "Dennis Groenendijk" <dennis.groenendijk@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
    Re: JTree forcing node to "Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
      Re: JTree forcing node to "Dennis Groenendijk" <dennis.groenendijk@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
        Re: JTree forcing node to "Lew" <lew@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
          Open source licenses Was: "Dennis Groenendijk" <dennis.groenendijk@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
  Re: JTree forcing node to lionelv@gmail.com.remove-dii-this - 2011-04-27 15:38 +0000
  Re: JTree forcing node to "bcd" <bcd@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
  Re: JTree forcing node to "Rogan Dawes" <rogan.dawes@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000

csiph-web