Example usage for javafx.scene.control TreeView setShowRoot

List of usage examples for javafx.scene.control TreeView setShowRoot

Introduction

In this page you can find the example usage for javafx.scene.control TreeView setShowRoot.

Prototype

public final void setShowRoot(boolean value) 

Source Link

Document

Specifies whether the root TreeItem should be shown within this TreeView.

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    rootNode.setExpanded(true);// w  w  w  . ja  v a 2 s.  c  om
    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 .  j a va2s .  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);/*from www  .ja va2 s . 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);/*from   ww w . j  a v 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();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    rootNode.setExpanded(true);//from w  ww  .j av a  2s . c  o m
    System.out.println(rootNode.toString());
    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.  j  a va  2  s  . com*/
    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:musicmetadatak1009705.FolderTreeView.java

public TreeView<File> proxyCreateNode(ArrayList<TreeItem> arrayListTreeItem) {
    TreeItem<File> proxyItem = new TreeItem<>();
    proxyItem.setExpanded(true);/*w  ww.j a v  a2 s .  c o m*/
    for (TreeItem<File> item : arrayListTreeItem) {
        proxyItem.getChildren().addAll(item);
    }
    TreeView<File> tree = new TreeView<>(proxyItem);
    tree.setShowRoot(false);
    return tree;
}

From source file:acmi.l2.clientmod.xdat.Controller.java

private TreeView<Object> createTreeView(Field listField, ObservableValue<String> filter) {
    TreeView<Object> elements = new TreeView<>();
    elements.setShowRoot(false);
    elements.setContextMenu(createContextMenu(elements));

    InvalidationListener treeInvalidation = (observable) -> buildTree(editor.xdatObjectProperty().get(),
            listField, elements, filter.getValue());
    editor.xdatObjectProperty().addListener(treeInvalidation);
    xdatListeners.add(treeInvalidation);

    filter.addListener(treeInvalidation);

    return elements;
}

From source file:be.makercafe.apps.makerbench.Main.java

/**
 * Creates the viewer control/*w  ww  .jav  a 2  s . co m*/
 *
 * @return
 */
private TreeView<String> createViewer() {
    TreeView<String> viewer = new TreeView<String>(setRootFolder(new File(this.pathMakerbenchHome)));
    viewer.setMinWidth(200.0);
    viewer.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    viewer.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {

            if (mouseEvent.getClickCount() == 2) {
                ResourceTreeItem<String> item = (ResourceTreeItem<String>) viewer.getSelectionModel()
                        .getSelectedItem();
                //               System.out.println("Selected Text : " + item.getValue());

                createEditor(item.getValue(), item.getPath(), null);
            } else if (mouseEvent.getButton() == MouseButton.SECONDARY) {
                ResourceTreeItem<String> item = (ResourceTreeItem<String>) viewer.getSelectionModel()
                        .getSelectedItem();
                if (item.getPath().toFile().isFile()) {
                    viewer.getContextMenu().getItems().get(0).setDisable(true);
                    viewer.getContextMenu().getItems().get(1).setDisable(true);
                    viewer.getContextMenu().getItems().get(2).setDisable(true);
                } else {
                    viewer.getContextMenu().getItems().get(0).setDisable(false);
                    viewer.getContextMenu().getItems().get(1).setDisable(false);
                    viewer.getContextMenu().getItems().get(2).setDisable(false);
                }
            }

        }
    });
    viewer.setContextMenu(rootContextMenu);
    viewer.setEditable(false);
    viewer.setShowRoot(false);

    return viewer;
}

From source file:utilitybasedfx.MainGUIController.java

private CheckBoxTreeItem<String> preSetupOpsTree(TreeView tree) {
    CheckBoxTreeItem<String> root = new CheckBoxTreeItem("root");

    root.setExpanded(true);/*from w  w w .  ja  v a 2s .  c o m*/

    tree.setStyle("-fx-font-size: 11; ");

    //tree.getStylesheets().add("/css/treeViewColouredSelection.css"); // [FIXME] make the color change! WHY IT NO WORK

    tree.setRoot(root);
    tree.setShowRoot(false);
    tree.setCellFactory(CheckBoxTreeCell.<String>forTreeView());

    return root;
}