2013-02-23 99 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

這是一個戲劇比喻 - 想象你正在看戲 - 這是羅密歐與朱麗葉,帷幕提起,你看到第一個場景(在維羅納的噴泉廣場)。後來,窗簾降下,小男人四處亂跑,換衣服,窗簾升起,你看到一個新的場景(朱麗葉臥室的陽臺)。場面改變了,但舞臺還沒有 - 只有一個舞臺和多個場景。

相關問題