在CheckboxTreeViewer中计算所选项

时间:2021-11-15 23:01:23

I have an issue when using CheckBoxTreeViewer. When I checked the child items, I want to show the count number of them in a label. Please help me!

使用CheckBoxTreeViewer时遇到问题。当我检查子项时,我想在标签中显示它们的计数。请帮我!

1 个解决方案

#1


1  

Assuming this is the Eclipse JFace CheckboxTreeViewer.

假设这是Eclipse JFace CheckboxTreeViewer。

Add a check state listener to the viewer using the addCheckStateListener method.

使用addCheckStateListener方法向查看器添加检查状态侦听器。

In the checkStateChanged method of the listener you can get the number of checked items and update your label.

在侦听器的checkStateChanged方法中,您可以获取已检查项的数量并更新标签。

Use the viewer getCheckedElements method of the viewer to get the number of checked elements:

使用查看器的viewer getCheckedElements方法获取已检查元素的数量:

Object [] elements = viewer.getCheckedElement();

int cout = elements.length;

#1


1  

Assuming this is the Eclipse JFace CheckboxTreeViewer.

假设这是Eclipse JFace CheckboxTreeViewer。

Add a check state listener to the viewer using the addCheckStateListener method.

使用addCheckStateListener方法向查看器添加检查状态侦听器。

In the checkStateChanged method of the listener you can get the number of checked items and update your label.

在侦听器的checkStateChanged方法中,您可以获取已检查项的数量并更新标签。

Use the viewer getCheckedElements method of the viewer to get the number of checked elements:

使用查看器的viewer getCheckedElements方法获取已检查元素的数量:

Object [] elements = viewer.getCheckedElement();

int cout = elements.length;