GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Tutorial 15 added. · VRR/Source-Code-from-Tutorials@4cde5ea

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • JavaFX/015_treeView
    • Main.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎JavaFX/015_treeView/Main.java‎

Copy file name to clipboard
+65Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import javafx.application.Application;
2+
import javafx.scene.Scene;
3+
import javafx.scene.control.TreeItem;
4+
import javafx.scene.control.TreeView;
5+
import javafx.scene.layout.StackPane;
6+
import javafx.stage.Stage;
7+
8+
public class Main extends Application {
9+
10+
Stage window;
11+
TreeView<String> tree;
12+
13+
public static void main(String[] args) {
14+
launch(args);
15+
}
16+
17+
@Override
18+
public void start(Stage primaryStage) {
19+
window = primaryStage;
20+
window.setTitle("JavaFX - thenewboston");
21+
22+
TreeItem<String> root, bucky, megan;
23+
24+
//Root
25+
root = new TreeItem<>();
26+
root.setExpanded(true);
27+
28+
//Bucky
29+
bucky = makeBranch("Bucky", root);
30+
makeBranch("thenewboston", bucky);
31+
makeBranch("YouTube", bucky);
32+
makeBranch("Chicken", bucky);
33+
34+
//Megan
35+
megan = makeBranch("Megan", root);
36+
makeBranch("Glitter", megan);
37+
makeBranch("Makeup", megan);
38+
39+
//Create the tree and hide the main Root
40+
tree = new TreeView<>(root);
41+
tree.setShowRoot(false);
42+
tree.getSelectionModel().selectedItemProperty()
43+
.addListener((v, oldValue, newValue) -> {
44+
if (newValue != null)
45+
System.out.println(newValue.getValue());
46+
});
47+
48+
//Layout
49+
StackPane layout = new StackPane();
50+
layout.getChildren().add(tree);
51+
Scene scene = new Scene(layout, 300, 250);
52+
window.setScene(scene);
53+
window.show();
54+
}
55+
56+
//Create branches
57+
public TreeItem<String> makeBranch(String title, TreeItem<String> parent) {
58+
TreeItem<String> item = new TreeItem<>(title);
59+
item.setExpanded(true);
60+
parent.getChildren().add(item);
61+
return item;
62+
}
63+
64+
65+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.