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">
バインド値を持つインスタンスを取得したい (この場合は name と呼ばれる TextField)
前もって感謝します