• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 440
  • Last Modified:

How do you delete a row from a JTree?

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
gusseology
Asked:
gusseology
3 Solutions
 
sciuriwareCommented:
Try:   JTree.removeSelectionRow(int row);

;JOOP!
0
 
gusseologyAuthor Commented:
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
 
gusseologyAuthor Commented:
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now