Solved

How do you delete a row from a JTree?

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cipher Configuration on Apache HTTPD 4 63
Basic Java Case or If-Else statement... 3 51
hibernate jars 4 32
Selenium docs api java index 3 19
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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:

831 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