get FXML file nodes using java code

老子叫甜甜 提交于 2019-12-07 07:41:43

问题


How to get elements or nodes from FXML file using Java, I know the way by using initialization or by setting controller class in FxmL . But I need to do it without any controller. I want to access the nodes inside the fxml file using.

My FXML COde:

HBox fx:id="hbx" id="hbx" alignment="CENTER_RIGHT" prefHeight="100.0"
prefWidth="200.0" BorderPane.alignment="CENTER"

My java Code

System.out.println(par.lookupAll("hbx"));

See my Code above, could you give me a hint?


回答1:


After loading the FXML file, you can use Node#lookup():

Node node = fxmlParentPane.lookup("#nodeId");


来源:https://stackoverflow.com/questions/22908074/get-fxml-file-nodes-using-java-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!