2013-02-23 50 views
0

我已经在锚点窗格中创建了fxml文件 但每次点击按钮我都会在新帧中获得下一个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); 
    } 
} 
+0

也许这可以帮助,它将一个FXML文件加载到AnchorPane中:http://stackoverflow.com/questions/14265697/bind-width-and-height-of-dynamically-loaded-fxml – Perneel 2013-02-24 14:59:15

回答

6

只需创建一个单一的Stage,当你要替换的阶段与新FXML的内容,新的FXML加载到一个新的Scene并调用stage.setScene

这是一个戏剧比喻 - 想象你正在看戏 - 这是罗密欧与朱丽叶,帷幕提起,你看到第一个场景(在维罗纳的喷泉广场)。后来,窗帘降下,小男人四处乱跑,换衣服,窗帘升起,你看到一个新的场景(朱丽叶卧室的阳台)。场面改变了,但舞台还没有 - 只有一个舞台和多个场景。

相关问题