我想从我用 FXMLoader 加载的场景中获取控制器。用例是:
- 我的 JSON 管理器收到一个 JSON 对象
我启动的任务显示了一个新场景,使用
Parent p = FXMLLoader.load(getClass().getResource("foo.fxml")); Scene scene = new Scene(p); stage.setScene(scene);
在那之后,我有空的场景。
现在我这样做是为了填充组件
AnchorPane pane = (AnchorPane)((AnchorPane) scene.getRoot()).getChildren().get(0); for(Node node : pane.getChildren()){ String id = node.getId(); if(id.equals(NAME)){ ((TextField)node).setText(value); } }
我的问题,有没有更简单的方法来做到这一点?我有一个在 FXML 中指定的控制器
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="526.0" minWidth="356.0" prefHeight="526.0" prefWidth="356.0"
xmlns:fx="http://javafx.com/fxml" fx:controller="bar.foo">
我想获取具有绑定值的实例(在这种情况下,TextField 称为名称)
提前致谢