Solved

How do you delete a row from a JTree?

Posted on 2006-11-20
5
387 Views
Last Modified: 2008-01-09
I created my own JTree model that takes a custom data structure and I build a JTree from the tree model.  That all works fine, the problem occurs when I try to delete a node from the tree.  I am not sure how to do this.  What approach would I use to delete a node and of course redisplay the tree without the node I just attempted to delete.  I'm only deleting the tree node, not the data from the data structure.

gusseology
0
Comment
Question by:gusseology
5 Comments
 
LVL 24

Assisted Solution

by:sciuriware
sciuriware earned 100 total points
ID: 17980118
Try:   JTree.removeSelectionRow(int row);

;JOOP!
0
 
LVL 14

Assisted Solution

by:hoomanv
hoomanv earned 100 total points
ID: 17980715
0
 
LVL 92

Accepted Solution

by:
objects earned 300 total points
ID: 17983163
0
 

Author Comment

by:gusseology
ID: 17983890
I'm sorry all, I should have explained it better.

I am not using default tree mode with mutale tree nodes.  I am using my own and therefore methods like removenodeFromParent() can not be used.

Basically what I did was remove the element from the data structure I am using, and remove it from it's parent, and then kill and rebuiild the tree.  This seems to be working okay.  So I am able to remove it now.  My problem now is not after removing it, autmoatically selecting it's parent.

I am able to automatically select its parent because I expand out all the rows, find the parent based on a piece of data, and select it.  The problem is ...I am not able to collapse all the other branches at that point!  grrr.  

I get the path to the element I want to select, and use setSelectionPath to do so, but that setSelectionPath takes in a TreePath and the tree path apparently includes everything expanded out.  So even though it is correctly selecting the right element.....it won't collapse all the other branches!  Anyone know how I might be able to do that??

gusseology
0
 

Author Comment

by:gusseology
ID: 18039290
I'm not really sure how to divide up the points.  I don't think either answer really answered the question, but my question was poorly written.

In the end, my solution was I simply delete the object, then rebuild the tree.

I'll split the points.

Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
nestparen challenge 4 57
mapBully challenge 6 93
word0 challenge 3 58
Securing Jmx Console and web console 2 48
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now