School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,158 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 4,053 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 Rate Topic: -----

#1 samgajjar  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 5
  • Joined: 19-March 09


Dream Kudos: 0

Post icon  Posted 19 March 2009 - 03:10 AM

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 March 2009 - 03:26 AM

Was This Post Helpful? 0
  • +
  • -


#2 pbl  Icon User is offline

  • Java Lover
  • Icon
  • Group: Mentors
  • Posts: 11,168
  • Joined: 06-March 08


Dream Kudos: 475

Posted 19 March 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
Was This Post Helpful? 0
  • +
  • -

#3 samgajjar  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 5
  • Joined: 19-March 09


Dream Kudos: 0

Posted 19 March 2009 - 09:55 PM

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 !


View Postpbl, on 19 Mar, 2009 - 02:21 PM, said:

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

Was This Post Helpful? 1

#4 pbl  Icon User is offline

  • Java Lover
  • Icon
  • Group: Mentors
  • Posts: 11,168
  • Joined: 06-March 08


Dream Kudos: 475

Posted 20 March 2009 - 04:24 PM

Post the code of your class extending TreeModel
Was This Post Helpful? 0
  • +
  • -

#5 samgajjar  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 5
  • Joined: 19-March 09


Dream Kudos: 0

Posted 23 March 2009 - 05:06 AM

View Postpbl, on 20 Mar, 2009 - 04:24 PM, said:

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 March 2009 - 05:24 AM

Was This Post Helpful? 0
  • +
  • -

#6 samgajjar  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 5
  • Joined: 19-March 09


Dream Kudos: 0

Posted 10 April 2009 - 05:27 AM

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... :-)
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

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

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month