Follow from the root node to the lower node with JavaFX ~ I know the directions ~

I'm currently creating an app using JavaFX, but now I need to dynamically remove or add nodes (components). However, there is almost no information to follow the node from the root node to the lower node, so we will describe the method by trial and error. (For now, I will only list the components I checked)

environment OS : macOS X Catalina Integrated development environment: Eclipse 2019-12 Java : AdoptOpenJDK 11.0.5 JavaFX : 11.0.2 SceneBuilder : 11.0

NodeTree


1:AnchorPane ← Root node ①
2: ┣━━━ MenuBar
3: ┣━┳━ AnchorPane ②
4: ┃ ┗━┳━ SplitPane ←Horizontal(Left and right split) ③
5: ┃   ┣━━━ AnchorPane
6: ┃   ┗━━━ PieChart ④
7: ┗━━━ AnchorPane

Follow the nodes in the order of ① ⇢ ② ⇢ ③ ⇢ ④.

sample.java


 1: public Scene setPieChart(Stage stage) {
 2:		Scene scene = stage.getScene();
 3:		AnchorPane ap2 = (AnchorPane)this.scene.getRoot(); ①
 4:		AnchorPane ap3 = (AnchorPane)ap2.getChildren().get(1); ②
 5:		SplitPane spHorizontal = (SplitPane)ap3.getChildren().get(0); ③
 6:		ObservableList<?> ol = (ObservableList<?>) spHorizontal.getItems(); ③
 7:		PieChart pieChart = (PieChart)ol.get(1); ④
 8:
 9:		return scene;
10: }

Note that if you try to get a child node of SplitPane, you will get an object of type ʻObservableList <?> With getItems () as in line 5. In this example, in the ʻObservableList <?> Type object, the 0th element is set to NodeTree ②AnchorPane, and the 1st element is set to PieChart`. That's why ol.get (1) is done on the 7th line of sample.java.

One more thing to note about the operation is that if the parent node of PieChart is a container such as AnchorPane, the drawn graph will not be scaled according to the resizing of the window. Therefore, Pie Chart is placed directly under Split Pane.

Another place that might get caught is ScrollPane. Specifically, assuming that the child node of ScrollPane is AnchorPane, the acquisition method of AnchorPane is as follows.

sample2.java


 1:	AnchorPane anchorPane = (AnchorPane) scrollPane.contentProperty().get();

That's all for the time being. Also, if it becomes necessary to investigate during development, I will add it.

It also serves as a memorandum of my own, but I hope it helps everyone.

Recommended Posts

Follow from the root node to the lower node with JavaFX ~ I know the directions ~
I tried upgrading from CentOS 6.5 to CentOS 7 with the upgrade tool
I wanted to make JavaFX programming easier with the Spring Framework
[Rails] I tried to raise the Rails version from 5.0 to 5.2
I tried to get the distance from the address string to the nearest station with ruby
I want to play with Firestore from Rails
[Java] I want to calculate the difference from the date
Tokoro I rewrote in the migration from Wicket 7 to 8
I want to know the answer of the rock-paper-scissors app
[Rails] I don't know how to use the model ...
I want to dark mode with the SWT app
I want to redirect sound from Ubuntu with xrdp
I want to fetch another association of the parent model from the intermediate table with has_many
I want to return a type different from the input element with Java8 StreamAPI reduce ()
I want to recreate the contents of assets from scratch in the environment built with capistrano
[JDBC] I tried to access the SQLite3 database from Java.
What I did in the version upgrade from Ruby 2.5.2 to 2.7.1
What I was addicted to with the Redmine REST API
I want to distinct the duplicated data with has_many through
I want to pass the startup command to postgres with docker-compose.
I tried to solve the problem of "multi-stage selection" with Ruby
I want to return to the previous screen with kotlin and java!
I tried to build the environment of PlantUML Server with Docker
I tried to implement the image preview function with Rails / jQuery
What I did in the migration from Spring Boot 1.4 series to 2.0 series
I tried to check the operation of gRPC server with grpcurl
What I did in the migration from Spring Boot 1.5 series to 2.0 series
[Java] I want to perform distinct with the key in the object
I tried to solve the paiza campaign problem "Challenge from Kaito 813"
[Android] I want to get the listener from the button in ListView