What are “nodes” in JavaFX / fxml?

What does the word "node" mean in the JavaFX / fxml context? If I search this question, I find that everyone is using the word "discuss something else", but there is no explanation For example, the answer to this question: how do I open the JavaFX filechooser from a controller class?:

What will the node be and how to "inject @ fxml"?

Solution

Node is an abstract superclass of graphic elements of scene graph "composed of"

Some examples of classes inherited from node:

>Textfield > anchorpane > canvas > group > V@R_489_2419 @> buttons > labels >

Inject the node with fxmlloader ID in this way:

>Create a field with the appropriate type in the controller associated with fxml (that is, any type that can be specified for the element to be injected) Fxmlloader must have access to this field, which means it must be public or annotated with @ fxml annotation. > Add the ID attribute from the fxml namespace (most likely using the prefix FX) to the element in the fxml file that should be injected The value of this attribute is the name of the field in the controller

example

FXML

....
<TextField fx:id="myTextField" ....>
....

Regulator

....
@FXML
private TextField myTextField;
....

Fxmlloader uses this information to assign the object created for the fxml element to the field before calling the initialize method of the controller

A complete example / extended guide containing injections can be found here: https://docs.oracle.com/javase/8/javafx/fxml-tutorial/fxml_tutorial_intermediate.htm#JFXMG153

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>