I am creating application in javaFX, Where I have used Treeview
with CheckBoxTreeItem of String as its nodes. I want to get all checked item in the treeview , How do I achieve that?
Heres code :
private TreeView<String> treeView_businessAreas;
Set<String> businessAreas = config.getBusinessAreas();
CheckBoxTreeItem<String> item = null;
for (String businessArea : businessAreas) {
item = new CheckBoxTreeItem<>(businessArea);
root.getChildren().add(item);
}
treeView_businessAreas.setRoot(root);
This is the code that you need:
treeView_businessAreas.getSelectionModel().getSelectedItems().addListener(new ListChangeListener<TreeItem>() {
@Override
public void onChanged(Change<? extends TreeItem> change) {
ObservableList<TreeItem<String>> allSelectedItems = (ObservableList<TreeItem<String>>) treeView_businessAreas.getSelectionModel().getSelectedItems();
//DO SOMETHING HERE WITH THE SELECTED ITEMS
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.