List of usage examples for javafx.scene.control TreeItem TreeItem
public TreeItem(final T value)
From source file:Main.java
@Override public void start(Stage primaryStage) { TreeItem<String> rootItem = new TreeItem<>("Root"); rootItem.setExpanded(true);//from www . j av a 2 s. c o m TreeItem<String> item = new TreeItem<>("A"); rootItem.getChildren().add(item); item = new TreeItem<>("B"); rootItem.getChildren().add(item); TreeView<String> tree = new TreeView<>(rootItem); StackPane root = new StackPane(); root.getChildren().add(tree); primaryStage.setScene(new Scene(root, 300, 250)); primaryStage.show(); }
From source file:Main.java
private TreeItem<File> createNode(final File f) { return new TreeItem<File>(f) { private boolean isLeaf; private boolean isFirstTimeChildren = true; private boolean isFirstTimeLeaf = true; @Override/* w w w .j av a 2s .c om*/ public ObservableList<TreeItem<File>> getChildren() { if (isFirstTimeChildren) { isFirstTimeChildren = false; super.getChildren().setAll(buildChildren(this)); } return super.getChildren(); } @Override public boolean isLeaf() { if (isFirstTimeLeaf) { isFirstTimeLeaf = false; File f = (File) getValue(); isLeaf = f.isFile(); } return isLeaf; } private ObservableList<TreeItem<File>> buildChildren(TreeItem<File> TreeItem) { File f = TreeItem.getValue(); if (f == null) { return FXCollections.emptyObservableList(); } if (f.isFile()) { return FXCollections.emptyObservableList(); } File[] files = f.listFiles(); if (files != null) { ObservableList<TreeItem<File>> children = FXCollections.observableArrayList(); for (File childFile : files) { children.add(createNode(childFile)); } return children; } return FXCollections.emptyObservableList(); } }; }
From source file:Main.java
private TreeItem<File> createNode(final File f) { return new TreeItem<File>(f) { private boolean isLeaf; private boolean isFirstTimeChildren = true; private boolean isFirstTimeLeaf = true; @Override/*from ww w . ja v a2s. c o m*/ public ObservableList<TreeItem<File>> getChildren() { if (isFirstTimeChildren) { isFirstTimeChildren = false; super.getChildren().setAll(buildChildren(this)); } return super.getChildren(); } @Override public boolean isLeaf() { if (isFirstTimeLeaf) { isFirstTimeLeaf = false; File f = (File) getValue(); isLeaf = f.isFile(); } return isLeaf; } private ObservableList<TreeItem<File>> buildChildren(TreeItem<File> TreeItem) { File f = TreeItem.getValue(); if (f != null && f.isDirectory()) { File[] files = f.listFiles(); if (files != null) { ObservableList<TreeItem<File>> children = FXCollections.observableArrayList(); for (File childFile : files) { children.add(createNode(childFile)); } return children; } } return FXCollections.emptyObservableList(); } }; }
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group()); stage.setTitle("Button Sample"); stage.setWidth(300);//from w w w . j a va 2 s . co m stage.setHeight(190); VBox vbox = new VBox(); vbox.setLayoutX(20); vbox.setLayoutY(20); TreeItem<String> root = new TreeItem<String>("Root Node"); root.setExpanded(true); root.getChildren().addAll(new TreeItem<String>("Item 1"), new TreeItem<String>("Item 2"), new TreeItem<String>("Item 3")); TreeView<String> treeView = new TreeView<String>(root); vbox.getChildren().add(treeView); vbox.setSpacing(10); ((Group) scene.getRoot()).getChildren().add(vbox); stage.setScene(scene); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { final Scene scene = new Scene(new Group(), 200, 400); Group sceneRoot = (Group) scene.getRoot(); TreeItem<String> childNode1 = new TreeItem<>("Node 1"); TreeItem<String> childNode2 = new TreeItem<>("Node 2"); TreeItem<String> childNode3 = new TreeItem<>("Node 3"); TreeItem<String> root = new TreeItem<>("Root"); root.setExpanded(true);/*w w w . j a va 2 s .c o m*/ root.getChildren().setAll(childNode1, childNode2, childNode3); TreeTableColumn<String, String> column = new TreeTableColumn<>("Column"); column.setPrefWidth(150); column.setCellValueFactory( (CellDataFeatures<String, String> p) -> new ReadOnlyStringWrapper(p.getValue().getValue())); TreeTableView<String> treeTableView = new TreeTableView<>(root); treeTableView.getColumns().add(column); sceneRoot.getChildren().add(treeTableView); stage.setScene(scene); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { rootNode.setExpanded(true);/* w ww . j a va 2 s .co m*/ for (Employee employee : employees) { TreeItem<String> empLeaf = new TreeItem<String>(employee.getName()); boolean found = false; for (TreeItem<String> depNode : rootNode.getChildren()) { if (depNode.getValue().contentEquals(employee.getDepartment())) { depNode.getChildren().add(empLeaf); found = true; break; } } if (!found) { TreeItem depNode = new TreeItem(employee.getDepartment()); rootNode.getChildren().add(depNode); depNode.getChildren().add(empLeaf); } } stage.setTitle("Tree View Sample"); VBox box = new VBox(); final Scene scene = new Scene(box, 400, 300); scene.setFill(Color.LIGHTGRAY); TreeView<String> treeView = new TreeView<String>(rootNode); treeView.setShowRoot(true); treeView.setEditable(true); box.getChildren().add(treeView); stage.setScene(scene); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { rootNode.setExpanded(true);//from w w w .j ava2s .com System.out.println(rootNode.isLeaf()); for (Employee employee : employees) { TreeItem<String> empLeaf = new TreeItem<String>(employee.getName()); boolean found = false; for (TreeItem<String> depNode : rootNode.getChildren()) { if (depNode.getValue().contentEquals(employee.getDepartment())) { depNode.getChildren().add(empLeaf); found = true; break; } } if (!found) { TreeItem depNode = new TreeItem(employee.getDepartment()); rootNode.getChildren().add(depNode); depNode.getChildren().add(empLeaf); } } stage.setTitle("Tree View Sample"); VBox box = new VBox(); final Scene scene = new Scene(box, 400, 300); scene.setFill(Color.LIGHTGRAY); TreeView<String> treeView = new TreeView<String>(rootNode); treeView.setShowRoot(true); treeView.setEditable(true); box.getChildren().add(treeView); stage.setScene(scene); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { rootNode.setExpanded(true);/* w ww . j a v a 2 s .c om*/ System.out.println(rootNode.isExpanded()); for (Employee employee : employees) { TreeItem<String> empLeaf = new TreeItem<String>(employee.getName()); boolean found = false; for (TreeItem<String> depNode : rootNode.getChildren()) { if (depNode.getValue().contentEquals(employee.getDepartment())) { depNode.getChildren().add(empLeaf); found = true; break; } } if (!found) { TreeItem depNode = new TreeItem(employee.getDepartment()); rootNode.getChildren().add(depNode); depNode.getChildren().add(empLeaf); } } stage.setTitle("Tree View Sample"); VBox box = new VBox(); final Scene scene = new Scene(box, 400, 300); scene.setFill(Color.LIGHTGRAY); TreeView<String> treeView = new TreeView<String>(rootNode); treeView.setShowRoot(true); treeView.setEditable(true); box.getChildren().add(treeView); stage.setScene(scene); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { rootNode.setExpanded(true);//w w w .ja v a 2 s . co m rootNode.setGraphic(rootIcon); for (Employee employee : employees) { TreeItem<String> empLeaf = new TreeItem<String>(employee.getName()); boolean found = false; for (TreeItem<String> depNode : rootNode.getChildren()) { if (depNode.getValue().contentEquals(employee.getDepartment())) { depNode.getChildren().add(empLeaf); found = true; break; } } if (!found) { TreeItem depNode = new TreeItem(employee.getDepartment()); rootNode.getChildren().add(depNode); depNode.getChildren().add(empLeaf); } } stage.setTitle("Tree View Sample"); VBox box = new VBox(); final Scene scene = new Scene(box, 400, 300); scene.setFill(Color.LIGHTGRAY); TreeView<String> treeView = new TreeView<String>(rootNode); treeView.setShowRoot(true); treeView.setEditable(true); box.getChildren().add(treeView); stage.setScene(scene); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { rootNode.setExpanded(true);/*from w w w.j av a2 s .co m*/ rootNode.setValue("new value"); for (Employee employee : employees) { TreeItem<String> empLeaf = new TreeItem<String>(employee.getName()); boolean found = false; for (TreeItem<String> depNode : rootNode.getChildren()) { if (depNode.getValue().contentEquals(employee.getDepartment())) { depNode.getChildren().add(empLeaf); found = true; break; } } if (!found) { TreeItem depNode = new TreeItem(employee.getDepartment()); rootNode.getChildren().add(depNode); depNode.getChildren().add(empLeaf); } } stage.setTitle("Tree View Sample"); VBox box = new VBox(); final Scene scene = new Scene(box, 400, 300); scene.setFill(Color.LIGHTGRAY); TreeView<String> treeView = new TreeView<String>(rootNode); treeView.setShowRoot(true); treeView.setEditable(true); box.getChildren().add(treeView); stage.setScene(scene); stage.show(); }