I have created a tree view using recursion, and it appears fine and allows me to check different items. However, when a button is pressed, I want to get all bottom level items.
At the moment I'm trying to print the selected items with this, but it only prints item the mouse has selected, rather than whatever items have been checked.
ObservableList<TreeItem<String>> tree = historicalDataTree.getSelectionModel().getSelectedItems();
for (TreeItem<String> treeItem : hello){
System.out.println(treeItem.getValue());
}
I am creating the tree with the two following methods
private void createTree(File dataFolder) {
CheckBoxTreeItem<String> rootItem = new CheckBoxTreeItem<>(dataFolder.getName());
historicalDataTree.setShowRoot(false);
historicalDataTree.setCellFactory(CheckBoxTreeCell.<String>forTreeView());
File fileList[] = dataFolder.listFiles();
for (File file : fileList) {
populateTree(file, rootItem);
}
historicalDataTree.setRoot(rootItem);
}
private void populateTree(File file, CheckBoxTreeItem<String> parent) {
if (file.isDirectory()) {
CheckBoxTreeItem<String> treeItem = new CheckBoxTreeItem<>(file.getName());
parent.getChildren().add(treeItem);
for (File f : file.listFiles()) {
populateTree(f, treeItem);
}
}
}
The tree can be seen here. If the tree had been selected like this and a button is clicked, I would like to have a list containing "2017" and any other items checked. Thanks.
Aucun commentaire:
Enregistrer un commentaire