【发布时间】:2016-05-14 20:45:24
【问题描述】:
我第一次在 JavaFX 项目上工作,这是我的问题:
我有一个 MainApp,从那里我打开主窗口,我有一个 MenuBar,从 MenuBar 我打开一个新窗口,这在 MainApp 的控制器中调用。
public void optionWindow() throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("/views/options.fxml"));
Stage stage = new Stage();
stage.setTitle("options");
stage.setScene(new Scene(root));
stage.setResizable(false);
stage.setAlwaysOnTop(true);
stage.show();
}
在这个新窗口中,我有两个按钮,其中一个应该使用 OptionsController 类中的方法打开一个 FileChooser。
public void updateOptions() {
FileChooser chooser = new FileChooser();
chooser.showOpenDialog(stage);
}
MainApp 启动方法:
@Override
public void start(Stage primaryStage) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("/views/Application.fxml"));
primaryStage.setTitle("Application");
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
我的问题是,我怎样才能获得舞台?因为 Stage 位于 MainAppController 类中。有没有什么流行的战争来获得阶段和主要阶段?
thx 4 阅读。
【问题讨论】: