Created
March 20, 2015 04:58
-
-
Save TheItachiUchiha/44202825a7c4b2b1cfa0 to your computer and use it in GitHub Desktop.
TreeViewSample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.application.Application; | |
import javafx.scene.Scene; | |
import javafx.scene.control.TreeItem; | |
import javafx.scene.control.TreeView; | |
import javafx.scene.layout.StackPane; | |
import javafx.stage.Stage; | |
import java.util.stream.Collectors; | |
import java.util.stream.IntStream; | |
public class TreeViewSample extends Application { | |
public static void main(String[] args) { | |
Application.launch(args); | |
} | |
@Override | |
public void start(Stage stage) { | |
TreeItem<String> rootItem = new TreeItem<>("Inbox"); | |
rootItem.setExpanded(true); | |
IntStream.range(0, 6) | |
.mapToObj(i -> new TreeItem<>("Message" + i)) | |
.collect(Collectors.toCollection(rootItem::getChildren)); | |
TreeItem<String> nested = new TreeItem<>("Nested"); | |
rootItem.getChildren().get(1).getChildren().add(nested); | |
rootItem.getChildren().get(1).setExpanded(true); | |
TreeView<String> tree = new TreeView<>(rootItem); | |
tree.setShowRoot(false); | |
stage.setScene(new Scene(new StackPane(tree), 300, 250)); | |
stage.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment