Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How do you delete a row from a JTree?

Posted on 2006-11-20
5
412 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

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

809 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