私はmaven、javafx、fxmlのプロジェクトを持っています。 1つのメインのBorderPane、welcome.fxml
、およびペイン、ready.fxml
があります。JavaFX別のペインの同じテキストエリア
私のスタートメソッドは;
@Override
public void start(Stage primaryStage) throws Exception {
try {
Pane root = (Pane) FXMLLoader.load(getClass().getResource("welcome.fxml"));
Scene scene = new Scene(root, 640, 480);
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
makeAlert(e, false);
}
}
は今、私は私のwelcome.fxml
のボタンを持っている、と私はready.fxml
と私のBorderPaneの中心部を変更したいです。ここに私のボタンハンドラがあります。
@FXML
private void buttonHandler() throws IOException, InterruptedException {
stage = (Stage) myButton.getScene().getWindow();
Pane sub = (Pane) FXMLLoader.load(getClass().getResource("../ready.fxml"));
BorderPane root = (BorderPane) FXMLLoader.load(getClass().getResource("../welcome.fxml"));
root.setCenter(sub);
//Scene scene = new Scene(root, 640, 480);
//stage.getScene().setRoot(root);
}
UPDATE:ここ@James_Dが気づいたように、私は私のコントローラで再びwelcome.fxml
を読み込むので、私の全体のシーンの変化は、中央のみのinsted、私のミスです。
正しい方法が必要です。
stage = (Stage) brokerConnect.getScene().getWindow();
Pane center = (Pane) FXMLLoader.load(getClass().getResource("../ready.fxml"));
// FIXME: Get root like this
BorderPane root = (BorderPane) stage.getScene().getRoot();
root.setCenter(center);
EDITED:Javaコードが追加されました。
は、なぜあなたはシーンの全体ルートを交換します窓?それが現れても、あなたの質問は本当に答えには向いていません...私は[MCVE]を作成し、それを含む質問を編集することをお勧めします。あなたが得る行動があなたが望む行動とどのように異なるのかを説明してください。 –
これを実行した後、 'root.setCenter(newPane);'センターが変更されていないので、私はrootSceneを置き換えます。私はちょうどJavaFXを学び始めました、私の無知のために申し訳ありません。 –
あなたが私たちに示していないコードで何か間違ったことをしています。あなたがここで不愉快なJavaFXを知らないわけではありません。誰かがそれに答える必要のある情報なしで質問を投稿したことです。 –