我已经在 anchor Pane 中创建了 fxml 文件 但每次我单击按钮时,我都会在新框架中得到下一个 fxml 我希望它在同一帧中打开
public void baropen(ActionEvent event) {
// handle the event here
BorderPane bp = new BorderPane();
bp.setPadding(new Insets(10, 50, 50, 50));
Stage stage = new Stage();
Scene scene ;
// scene= new Scene(root);
scene = new Scene(bp);
stage.setScene(scene);
stage.show();
try {
new RecBar().start(stage);
} catch (Exception ex) {
Logger.getLogger(RecController.class.getName()).log(Level.SEVERE, null,ex);
}
}
最佳答案
只需创建一个 Stage
,当您想用新的 fxml 替换舞台内容时,将新的 fxml 加载到新的 Scene
中并调用 stage.setScene
.
这是一个戏剧隐喻 - 想象你正在看一场戏剧 - 这是罗密欧与朱丽叶,帷幕升起,你看到第一个场景(维罗纳的一个有喷泉的广场)。随后,窗帘降下,小人物跑来跑去换东西,窗帘升起,你看到一个新的场景(朱丽叶卧室的阳台)。场景变了,但舞台没变——只有一个舞台,多个场景。
关于java - 是否可以在同一框架中打开新的 fxml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15039344/