【问题标题】:is it possible to open a new fxml file in the same frame是否可以在同一帧中打开一个新的 fxml 文件
【发布时间】:2013-02-23 10:11:51
【问题描述】:

我在锚窗格中创建了 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);
    }
}

【问题讨论】:

标签: java javafx-2 javafx


【解决方案1】:

只需创建一个Stage,当您想用新的fxml替换舞台的内容时,将新的fxml加载到新的Scene并调用stage.setScene

这是一个戏剧隐喻 - 假设您正在观看一场戏剧 - 这是罗密欧与朱丽叶,大幕拉开,您看到了第一个场景(维罗纳的一个带有喷泉的广场)。稍后,窗帘拉下,小人跑来跑去换东西,窗帘升起,你看到了一个新的场景(朱丽叶卧室的阳台)。场景变了,但舞台没有变——只有一个舞台和多个场景。

【讨论】:

    猜你喜欢
    • 2017-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多