Created
October 16, 2017 15:47
-
-
Save tanmatra/a2dba1733aa3c6e69b648c663fd3fcdc to your computer and use it in GitHub Desktop.
JavaFX TreeTableView bug in Java 9
This file contains 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 java.util.Random; | |
import javafx.application.Application; | |
import javafx.beans.property.ReadOnlyIntegerWrapper; | |
import javafx.beans.property.ReadOnlyStringWrapper; | |
import javafx.scene.Node; | |
import javafx.scene.Scene; | |
import javafx.scene.control.TreeItem; | |
import javafx.scene.control.TreeTableColumn; | |
import javafx.scene.control.TreeTableView; | |
import javafx.scene.layout.BorderPane; | |
import javafx.scene.paint.Color; | |
import javafx.scene.shape.Circle; | |
import javafx.stage.Stage; | |
public class TreeTableViewTestApp extends Application | |
{ | |
private static final Color CATEGORY_COLOR = new Color(1.0, 1.0, 0.7, 1.0); | |
private static final Color TOPIC_COLOR = new Color(0.7, 1.0, 1.0, 1.0); | |
private static final Random random = new Random(); | |
private static Node createCircle(Color color) { | |
final Circle circle = new Circle(4.0); | |
circle.setFill(color); | |
circle.setStroke(Color.BLACK); | |
circle.setStrokeWidth(0.5); | |
return circle; | |
} | |
public static void main(String[] args) { | |
Application.launch(args); | |
} | |
@Override | |
public void start(Stage primaryStage) throws Exception { | |
final TreeItem<String> rootItem = new TreeItem<>("Root"); | |
rootItem.setGraphic(createCircle(new Color(1.0, 0.7, 1.0, 1.0))); | |
for (int i = 0; i < 5; i++) { | |
final TreeItem<String> categoryItem = new TreeItem<>("Category " + i); | |
categoryItem.setGraphic(createCircle(CATEGORY_COLOR)); | |
rootItem.getChildren().add(categoryItem); | |
for (int j = 0; j < 5; j++) { | |
final TreeItem<String> topicItem = new TreeItem<>("Topic " + (i * 10 + j)); | |
topicItem.setGraphic(createCircle(TOPIC_COLOR)); | |
categoryItem.getChildren().add(topicItem); | |
} | |
} | |
final TreeTableView<String> treeTableView = new TreeTableView<>(rootItem); | |
final TreeTableColumn<String, String> column1 = new TreeTableColumn<>(); | |
column1.setText("Name"); | |
column1.setPrefWidth(300.0); | |
column1.setCellValueFactory(features -> new ReadOnlyStringWrapper(features.getValue().getValue())); | |
final TreeTableColumn<String, Number> column2 = new TreeTableColumn<>(); | |
column2.setText("Size"); | |
column2.setPrefWidth(100.0); | |
column2.setCellValueFactory(features -> new ReadOnlyIntegerWrapper(random.nextInt(1000))); | |
treeTableView.getColumns().addAll(column1, column2); | |
final BorderPane borderPane = new BorderPane(treeTableView); | |
final Scene scene = new Scene(borderPane); | |
primaryStage.setScene(scene); | |
primaryStage.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment