Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #2298 > unrolled thread
| Started by | lionelv@gmail.com.remove-dii-this |
|---|---|
| First post | 2011-04-27 15:38 +0000 |
| Last post | 2011-04-27 15:38 +0000 |
| Articles | 9 — 6 participants |
Back to article view | Back to comp.lang.java.gui
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
| From | lionelv@gmail.com.remove-dii-this |
|---|---|
| Date | 2011-04-27 15:38 +0000 |
| Subject | JTree forcing node to hav |
| Message-ID | <1187739706.626536.157780@x40g2000prg.googlegroups.com> |
To: comp.lang.java.gui 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. --- * 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
[toc] | [next] | [standalone]
| From | "Dennis Groenendijk" <dennis.groenendijk@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:38 +0000 |
| Subject | Re: JTree forcing node to |
| Message-ID | <46cb7e88$0$237$e4fe514c@news.xs4all.nl> |
| In reply to | #2298 |
To: comp.lang.java.gui
>
>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.
---
* 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
[toc] | [prev] | [next] | [standalone]
| From | "Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:38 +0000 |
| Subject | Re: JTree forcing node to |
| Message-ID | <46cd0359$0$15355$4c368faf@roadrunner.com> |
| In reply to | #2299 |
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
[toc] | [prev] | [next] | [standalone]
| From | "Dennis Groenendijk" <dennis.groenendijk@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:38 +0000 |
| Subject | Re: JTree forcing node to |
| Message-ID | <46dd8459$0$241$e4fe514c@news.xs4all.nl> |
| In reply to | #2309 |
To: comp.lang.java.gui Hi Brandon, >> 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 It is a bit off-topic so a short reply: Yes it handles binaries and you can find an early beta on http://www.brains2b.org/project/CoffeeBreak/project.html It is published under the modified BSD-license (no copyleft) so you can also find the sources. Regards, Dennis --- * 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
[toc] | [prev] | [next] | [standalone]
| From | "Lew" <lew@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:38 +0000 |
| Subject | Re: JTree forcing node to |
| Message-ID | <Ru2dnWVAy-qLRUDbnZ2dnUVZ_ozinZ2d@comcast.com> |
| In reply to | #2367 |
To: comp.lang.java.gui Dennis Groenendijk wrote: > It is published under the modified BSD-license (no copyleft) so you can also find the sources. What do you mean by "no copyleft"? Isn't BSD an open-source license, therefore by definition it is "copyleft"? -- Lew --- * 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
[toc] | [prev] | [next] | [standalone]
| From | "Dennis Groenendijk" <dennis.groenendijk@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:38 +0000 |
| Subject | Open source licenses Was: |
| Message-ID | <46dde952$0$236$e4fe514c@news.xs4all.nl> |
| In reply to | #2369 |
To: comp.lang.java.gui Hi Lew, >Dennis Groenendijk wrote: >> It is published under the modified BSD-license (no copyleft) so you can also find the sources. >What do you mean by "no copyleft"? Isn't BSD an open-source license, >therefore by definition it is "copyleft"? >-- >Lew I don't want to start a discussion on open source licenses here, but I do feel the need to clarify. There are basically 3 different forms of open source licenses: - The copy-left: which means every derivative work of the original should be published under the same license, thus making sure all derivative works are open source as well. The GPL is the best example - The non-copy-left: which means a derivative work does not have to be published under the same license and can be published under a commercial license if one wishes. The BSD, Eclipse public license and LGPL are examples of this. - Enumerated rights license: Means that within the license the way a work can be used to derive other works from are either enumerated or an enumeration of exclusions for derivative works is included in the license. You find this in de creative commons licenses that spring up. My newsreader is published under the modified BSD license (the default of the foundation that publishes it), so you can use the source code to improve the newsreader and give back, which I hope, or make your own derivative work with another license (even commercial). You cannot however change the license of the original code. Hope this clarifies it. Regards, Dennis.. --- * 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
[toc] | [prev] | [next] | [standalone]
| From | lionelv@gmail.com.remove-dii-this |
|---|---|
| Date | 2011-04-27 15:38 +0000 |
| Subject | Re: JTree forcing node to |
| Message-ID | <1187742470.777678.271750@l22g2000prc.googlegroups.com> |
| In reply to | #2298 |
To: comp.lang.java.gui On Aug 22, 9:41 am, "lion...@gmail.com" <lion...@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. I got around it (with a hack) by extending DefaultTreeCellRenderer and in the getTreeCellRendererComponent method I do a check to see if it is a Directory node. If it is I call the parent getTreeCellRendererComponent with leaf parameter of false which returns the icon I want. The only problem is that for some really strange reason it is not using the windows look and feel now. I set the look and feel right at the start and as it was I had to force the JTree to adopt it, but now that isn't working either and it is going back to default look and feel. Any ideas on that one? What I did shouldn't have effected this. Thanks Lionel. --- * 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
[toc] | [prev] | [next] | [standalone]
| From | "bcd" <bcd@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:38 +0000 |
| Subject | Re: JTree forcing node to |
| Message-ID | <fagvnp$c2b$2@orkan.itea.ntnu.no> |
| In reply to | #2298 |
To: comp.lang.java.gui
In article <1187739706.626536.157780@x40g2000prg.googlegroups.com>,
lionelv@gmail.com <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?
Override TreeModel.isLeaf() to return false for all your directory
nodes.
Cheers
Bent D
--
Bent Dalager - bcd@pvv.org - http://www.pvv.org/~bcd
powered by emacs
---
* 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
[toc] | [prev] | [next] | [standalone]
| From | "Rogan Dawes" <rogan.dawes@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:38 +0000 |
| Subject | Re: JTree forcing node to |
| Message-ID | <a8udnX8_PJa3mFHbRVnyjQA@saix.net> |
| In reply to | #2298 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.gui
csiph-web