Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #2309
| From | "Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Re: JTree forcing node to |
| Message-ID | <46cd0359$0$15355$4c368faf@roadrunner.com> (permalink) |
| Newsgroups | comp.lang.java.gui |
| References | <46cb7e88$0$237$e4fe514c@news.xs4all.nl> |
| Date | 2011-04-27 15:38 +0000 |
| Organization | TDS.net |
To: comp.lang.java.gui
Dennis Groenendijk 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.
>
> The simplest solution I can think of is doing this:
>
> public class MyTreeCellRenderer extends DefaultTreeCellRenderer {
>
> public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel,
> boolean expanded, boolean leaf, int row, boolean hasFocus) {
>
> if (leaf && tree.getPathForRow(row).getLastPathComponent() instanceof DirectoryNode) {
> //or some other way you detect the difference between your nodes
> setLeafIcon(getClosedIcon());
> }
> return super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
> row, hasFocus);
> }
> }
>
> you do have to set
> tree.setCellRenderer(new MyTreeCellRenderer());
> on your tree.
>
> Hope this helps.
>
> Dennis.
>
> This message was written with a newsreader I am writing in Java. So if there is something wrong
> with the message my apologies to the poster and more testing for me before release.
I'd be interested in testing your newsreader if you are allowing outside
testers access to the program. I'd use it in Windows XP but since it
is written in Java that shouldn't be a problem. Can it handle binary
attachments yet?
Brandon
---
* 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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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