Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a Java Expert!

Join 306,830 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,747 people online right now. Registration is fast and FREE... Join Now!




How to remove leaf nodes in JAVA Tree ?

 

How to remove leaf nodes in JAVA Tree ?, I want to remove leaf (child) nodes from jtree

samgajjar

19 Mar, 2009 - 03:10 AM
Post #1

New D.I.C Head
*

Joined: 19 Mar, 2009
Posts: 5



Thanked: 1 times
My Contributions
I made a software to display the tree sturcture just like a windows explorer. As in windows explorer we have two panels.

1. Left panel (folder display view in tree manner)
2. Right panel (where we can see available files in a folder)

If i expand the folder on the left panel it is showing me files as a part of a folder.
So I want that if I click on the folder it should shows all the leaf modes ( files) on the right side and not on the left side. Inshort I want to hide these files on the left side as a part of a folder. how can I do this in JAVA SWING ????

can anybody give me a hint or source code or any idea ?

This post has been edited by samgajjar: 19 Mar, 2009 - 03:26 AM

User is offlineProfile CardPM
+Quote Post


pbl

RE: How To Remove Leaf Nodes In JAVA Tree ?

19 Mar, 2009 - 02:21 PM
Post #2

Java Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 9,962



Thanked: 1187 times
Dream Kudos: 450
My Contributions
JTree display the nodes that it's TreeModel tells him to display
So you will have to have 2 different TreeModel
one for the left panel that does return nothing to display for the file nodes
one for the right panel that returns the file nodes

Actually you should create only one class doing that and having a boolean in the constructor that specifies if you should display the file nodes or not.

Happy coding
User is online!Profile CardPM
+Quote Post

samgajjar

RE: How To Remove Leaf Nodes In JAVA Tree ?

19 Mar, 2009 - 09:55 PM
Post #3

New D.I.C Head
*

Joined: 19 Mar, 2009
Posts: 5



Thanked: 1 times
My Contributions
In "figure- ANQuery_1.JPG" you can see as all the child values of "folder 1" displayed on the left panel as well as on the right panel.

Attached Image

I want to display values of "folder 1" only on the right panel (as shown in "figure-ANQuery_1_Solution.JPG").

Attached Image

Do you have any idea for JAVA swing ? compare 'folder-1' and 'folder-2' results in both the images to get better idea. Please let me know in case of any query. Thanking you for anticipation. (NOTE: "figure-ANQuery_1_Solution.JPG" is just a snapshot).

( if you cant see the figure Please find the attachement for both the fiiles)

Hey thanks for your comments and guidance. Can you please give the solution for the specific requirement for our query I posted below ???? Thanks !


QUOTE(pbl @ 19 Mar, 2009 - 02:21 PM) *

JTree display the nodes that it's TreeModel tells him to display
So you will have to have 2 different TreeModel
one for the left panel that does return nothing to display for the file nodes
one for the right panel that returns the file nodes

Actually you should create only one class doing that and having a boolean in the constructor that specifies if you should display the file nodes or not.

Happy coding



User is offlineProfile CardPM
+Quote Post

pbl

RE: How To Remove Leaf Nodes In JAVA Tree ?

20 Mar, 2009 - 04:24 PM
Post #4

Java Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 9,962



Thanked: 1187 times
Dream Kudos: 450
My Contributions
Post the code of your class extending TreeModel
User is online!Profile CardPM
+Quote Post

samgajjar

RE: How To Remove Leaf Nodes In JAVA Tree ?

23 Mar, 2009 - 05:06 AM
Post #5

New D.I.C Head
*

Joined: 19 Mar, 2009
Posts: 5



Thanked: 1 times
My Contributions
QUOTE(pbl @ 20 Mar, 2009 - 04:24 PM) *

Post the code of your class extending TreeModel


Hi,
I have stored my treemodel into another tree model and used getTreeCellRendrerComponenet to hide leaf nodes from the first tree model,
the part of code goes like this:

Ref_Tree.getTreeCellRendrerComponent(value,leaf,sel.......)
{
if (!leaf)
{
super.getTreeCellRendererComponent(tree,value, sel, expanded,leaf, row, hasFocus);
}
else
{
super.getTreeCellRendererComponent(tree," ", sel, expanded,leaf, row, hasFocus);
}
return this;
}

As you can see , i have assigned null string to "value" in the else statement. This null string appears in the JTree display when i display JTree in left panel(jScroolpane). I want to remove this null string , another problem i face is, i do not want to display expand icon (like '+') when the node has its all children are leaf nodes. you can refer the images which i posted in my last post. Thanks for the help.



This post has been edited by samgajjar: 23 Mar, 2009 - 05:24 AM
User is offlineProfile CardPM
+Quote Post

samgajjar

RE: How To Remove Leaf Nodes In JAVA Tree ?

10 Apr, 2009 - 05:27 AM
Post #6

New D.I.C Head
*

Joined: 19 Mar, 2009
Posts: 5



Thanked: 1 times
My Contributions
can any one reply to this post ? Its bit urgent so thank you very much in advance for anticipating........ Please reply as soon as possible . If you are in my region I will give you a small treat for sure... :-)
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/20/09 10:45PM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month