简体   繁体   English

如何在Java SWT中从树中删除TreeItem?

[英]How to remove a TreeItem from a Tree in java SWT?

I am using java SWT for an application development. 我正在使用java SWT进行应用程序开发。

There is a SWT Tree with some child nodes in the tool and I want to delete some of them. 有一个SWT树,工具中有一些子节点,我想删除其中的一些。 I tried using remove() and removeAll() methods but it does not delete the item completely. 我尝试使用remove()和removeAll()方法,但它不会完全删除该项目。 It leaves behind a space for TreeItem. 它为TreeItem留下了一个空间。

在此输入图像描述

根据这篇文章 ,您应该在要完全删除的树项上使用item.dispose()

TreeItem is a descendant of Widget which contains the dispose() method. TreeItemWidget的后代,它包含dispose()方法。 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(). 调用此方法后,接收方和所有后代将在发送消息isDisposed()时回答true。 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. 所以treeItem.dispose()将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM