import javafx.application.Application; import javafx.geometry.Insets; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TreeItem; import javafx.scene.control.TreeView; import javafx.scene.layout.VBox; public class App extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) throws Exception { TreeView tree; TreeItem rootNode, progNode, databaseNode; rootNode = new TreeItem<>("Tanulnivaló"); progNode = createNode("Programozás", rootNode); createNode("Java", progNode); createNode("Charp", progNode); databaseNode = createNode("Adatbázis", rootNode); createNode("MySQL", databaseNode); createNode("Mariadb", databaseNode); tree = new TreeView<>(rootNode); Button button = new Button("Vált"); button.setOnAction(e -> { if (tree.isShowRoot()) tree.setShowRoot(false); else tree.setShowRoot(true); }); VBox vbox = new VBox(10); vbox.setPadding(new Insets(10, 10, 10, 10)); vbox.getChildren().addAll(tree, button); Scene scene = new Scene(vbox, 300, 250); primaryStage.setScene(scene); primaryStage.show(); } public TreeItem createNode(String title, TreeItem parent) { TreeItem node = new TreeItem<>(title); parent.getChildren().add(node); return node; } }