2014-01-21 3 views
0

몇 가지 메뉴가있는 주 fxml 파일이 있습니다. 사용자가 특정 버튼을 클릭하면 내용이 변경되며이 내용은 주 화면에로드되는 별도의 fxml 파일입니다. 전체 장면은 변경되지 않지만 장면의 일부분 만 변경됩니다. 여기에 내가 만들고 싶어 응용 프로그램의 간단한 프로토 타입입니다! [1]주 fxml 파일에 fxml 파일로드

https://www.dropbox.com/s/3nildyt004v32vc/fxml%20application.png

답변

0

이 시도 [여기 이미지에 대한 설명을 입력] ..

AnchorPane pane; // pane where fxml was showing 
    menu1.setOnAction(new EventHandler<ActionEvent>() { 
    @Override 
    public void handle(ActionEvent t) { 
     openNewWindow("m1.fxml"); 

    } 
    }); 
    menu2.setOnAction(new EventHandler<ActionEvent>() { 
    @Override 
    public void handle(ActionEvent t) {    
     openNewWindow("m2.fxml"); 

    }}); 
    menu3.setOnAction(new EventHandler<ActionEvent>() { 
    @Override 
    public void handle(ActionEvent t) {    
     openNewWindow("m3.fxml"); 

    } 
    }); 

기능 openNewWindow

public void openNewWindow(String FXMLFile) 
{ 
    //ChildNode child; 
    try {      
     URL url = getClass().getResource(FXMLFile); 
     FXMLLoader fxmlLoader = new FXMLLoader(); 
     fxmlLoader.setLocation(url); 
     fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory()); 
     AnchorPane page = (AnchorPane) fxmlLoader.load(url.openStream()); 

     Pane.getChildren().clear();///name of pane where you want to put the fxml 
     Pane.getChildren().add(page); 
    } 
    catch (IOException e) { 
     e.printStackTrace(); 
    } 
}