Example usage for javafx.scene.control TreeView setEditable

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

Introduction

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

Prototype

public final void setEditable(boolean value) 

Source Link

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    CheckBoxTreeItem<String> rootItem = new CheckBoxTreeItem<>("A");
    rootItem.setExpanded(true);/*from   www .  j ava 2s . c o  m*/

    TreeView tree = new TreeView(rootItem);
    tree.setEditable(true);

    tree.setCellFactory(CheckBoxTreeCell.forTreeView());

    CheckBoxTreeItem<String> checkBoxTreeItem = new CheckBoxTreeItem<>("a");
    rootItem.getChildren().add(checkBoxTreeItem);

    checkBoxTreeItem = new CheckBoxTreeItem<>("b");
    rootItem.getChildren().add(checkBoxTreeItem);

    tree.setRoot(rootItem);

    StackPane root = new StackPane();
    root.getChildren().add(tree);
    primaryStage.setScene(new Scene(root, 300, 250));
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    rootNode.setExpanded(true);//from   w ww. j av  a 2  s  . com
    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  a va2 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);//from   w ww. ja v a2  s  .  c  om
    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 w w  w .  j av a 2  s.c  om*/
    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 ww w . ja  v  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);/*from  w  w  w.j  ava2  s  .  c o  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  a  v a2s  .co  m*/
    for (Employee employee : employees) {
        TreeItem<String> empLeaf = new TreeItem<>(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<String> 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<>(rootNode);
    treeView.setEditable(true);
    treeView.setCellFactory((TreeView<String> p) -> new TextFieldTreeCellImpl());

    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 . ja va 2  s  .  co m
    for (Employee employee : employees) {
        TreeItem<String> empLeaf = new TreeItem<>(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<>(rootNode);
    treeView.setEditable(true);
    treeView.setCellFactory((TreeView<String> p) -> new TextFieldTreeCellImpl());

    box.getChildren().add(treeView);
    stage.setScene(scene);
    stage.show();
}

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

/**
 * Creates the viewer control/*  ww  w  .j a  va2 s . c  o 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;
}