Example usage for javafx.scene.control TreeView setRoot

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

Introduction

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

Prototype

public final void setRoot(TreeItem<T> value) 

Source Link

Document

Sets the root node in this TreeView.

Usage

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

private static void buildTree(IOEntity entity, Field listField, TreeView<Object> elements, String nameFilter) {
    elements.setRoot(null);

    if (entity == null)
        return;//from  w  ww .  j  a  v  a  2  s  .  c  om

    try {
        List<IOEntity> list = (List<IOEntity>) listField.get(entity);
        if (!listField.isAnnotationPresent(Type.class)) {
            log.log(Level.WARNING, String.format("XDAT.%s: @Type not defined", listField.getName()));
            Dialogs.show(Alert.AlertType.ERROR, "ReflectiveOperationException", null,
                    String.format("XDAT.%s: @Type not defined", listField.getName()));
        } else {
            Class<? extends IOEntity> type = listField.getAnnotation(Type.class).value()
                    .asSubclass(IOEntity.class);
            TreeItem<Object> rootItem = new TreeItem<>(new ListHolder(entity, list, listField.getName(), type));

            elements.setRoot(rootItem);

            rootItem.getChildren().addAll(list.stream().map(Controller::createTreeItem)
                    .filter(treeItem -> checkTreeNode(treeItem, nameFilter)).collect(Collectors.toList()));
        }
    } catch (IllegalAccessException e) {
        log.log(Level.WARNING, String.format("%s.%s is not accessible",
                listField.getDeclaringClass().getSimpleName(), listField.getName()), e);
        Dialogs.show(Alert.AlertType.ERROR, "ReflectiveOperationException", null,
                listField.getDeclaringClass().getSimpleName() + "." + listField.getName()
                        + " is not accessible");
    }
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    CheckBoxTreeItem<String> rootItem = new CheckBoxTreeItem<>("A");
    rootItem.setExpanded(true);/*  w w  w.  j a  va2  s . com*/

    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:utilitybasedfx.MainGUIController.java

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

    root.setExpanded(true);//  ww  w  .  j av a2 s. com

    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;
}