Cjo
Cjo

Reputation: 1351

How to remove a TreeItem from a Tree in java SWT?

I am using java SWT for an application development.

There is a SWT Tree with some child nodes in the tool and I want to delete some of them. I tried using remove() and removeAll() methods but it does not delete the item completely. It leaves behind a space for TreeItem.

enter image description here

Upvotes: 2

Views: 2540

Answers (2)

Abhiroop Sarkar
Abhiroop Sarkar

Reputation: 2311

TreeItem is a descendant of Widget which contains the dispose() method. According to documentation:

Disposes of the operating system resources associated with the receiver and all its descendants. After this method has been invoked, the receiver and all descendants will answer true when sent the message isDisposed(). Any internal connections between the widgets in the tree will have been removed to facilitate garbage collection. This method does nothing if the widget is already disposed.

So treeItem.dispose() will work.

Upvotes: 5

Mr Rho
Mr Rho

Reputation: 578

According to this post, you should use item.dispose() on the treeitem you want to completely remove.

Upvotes: 5

Related Questions