/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package tests; import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.SelectionMode; import javafx.scene.control.TreeItem; import javafx.scene.control.TreeView; import javafx.scene.input.KeyEvent; import javafx.scene.input.MouseEvent; import javafx.scene.layout.HBox; import javafx.stage.Stage; /** * * @author sjiang */ public class MyTreeViewTest2 extends Application { public static void main(String[] args) throws Exception { Application.launch(args); } @Override public void start(Stage stage) throws Exception { final TreeView treeView1 = new TreeView(); treeView1.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); treeView1.setPrefSize(300, 300); TreeItem root1 = new TreeItem("Root"); root1.setExpanded(true); addChildren(root1, "child"); for (TreeItem child : root1.getChildren()) { addChildren(child, (String)child.getValue()); child.setExpanded(true); } treeView1.setRoot(root1); // HBox hbox = new HBox(); // hbox.getChildren().setAll(treeView1); Scene scene = new Scene(treeView1); stage.setScene(scene); stage.show(); } private void addChildren(TreeItem parent, String name) { for (int i=0; i<3; i++) { TreeItem ti = new TreeItem(name+"-"+i); parent.getChildren().add(ti); } } }