2015-11-20 39 views
0

當我單擊超鏈接時,我想更改位於主應用程序邊框窗格中心的場景。所以,我編寫我的程序如下JavaFX:如何更改包含在BorderPane中心的場景

private BorderPane borderPane; 
    private AnchorPane connectionPage; 
    @FXML 
    private Hyperlink hyperLink1; 

    @FXML 
    private void handleHyperLink1OnAction() { 
     try { 
      connectionPage=FXMLLoader.load(getClass().getResource("ConnectionViewer.fxml")); 
     } catch (Exception e) { 
      System.out.println(e.getStackTrace().toString()); 
      System.out.println(e.getMessage()); 
     } 
     borderPane.setCenter(connectionPage); 
    } 

這是我的主要應用

public void start(Stage primaryStage) throws Exception { 
     Parent welcomePage = FXMLLoader.load(getClass().getResource("ManagerWorldViewer.fxml")); 

     Scene scene = new Scene(welcomePage); 

     primaryStage.setScene(scene); 
     primaryStage.show(); 
    } 

一旦我運行這個程序,沒有什麼變化,沒有出現錯誤。請幫我

+0

是否有borderpane @FXML註釋? –

+0

噢,我..我忘記了,非常感謝 – James

回答

0

我錯過了@FXML註釋。所以我改變了我的源代碼。..

@FXML 
    private BorderPane borderPane; 
@FXML 
    private AnchorPane anchorPane; 

private void changeScreenOfCenter(String path, VBox menuVBox) { 
     VBox getVbox = menuVBox; 
     try { 
      anchorPane = FXMLLoader.load(getClass().getResource(path)); 
     } catch (Exception e) { 
      System.out.println(e.getStackTrace().toString()); 
      System.out.println(e.getMessage()); 
     } 
} 

它的工作原理。