2014-11-26 3 views
14

javafx에서 버튼을 사용하여 다른 fxml의 새 단계 (창)를 열 수 있습니까? 답변 해 주셔서 감사합니다. 내가 코드를 조금 수정했다Javafx 버튼을 사용하여 다른 창에서 다른 fxml을 엽니 다.

 try{ 
      FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("Demo.fxml")); 
      Parent root1 = (Parent) fxmlLoader.load(); 
      Stage stage = new Stage(); 
      stage.initModality(Modality.APPLICATION_MODAL); 
      stage.initStyle(StageStyle.UNDECORATED); 
      stage.setTitle("ABC"); 
      stage.setScene(new Scene(root1)); 
      stage.show(); 
      } 
+0

예. 몇 가지 코드를 보여주고 어떤 부분에 붙어 있는지 설명해 주시겠습니까? –

답변

34

사용을 클릭하고 그것을 잘 작동합니다. 코드를 다시 한번 감사드립니다!

public void pressButton(ActionEvent event) throws Exception {    
     try { 
     FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/A.fxml")); 
       Parent root1 = (Parent) fxmlLoader.load(); 
       Stage stage = new Stage(); 
       stage.setScene(new Scene(root1)); 
       stage.show(); 
     } catch(Exception e) { 
      e.printStackTrace(); 
      } 
} 
+0

이 코드를 사용해 주셔서 감사합니다.하지만 창을 별도로 이동하고 오른쪽 상단을 닫을 수 있습니다. – Sevi

+0

이 코드가 유용하다고 생각한다면 투표를하십시오. – SimplyMe

+0

스타일을 사용하여 창 주석 행을 이동하고 닫으려면 : StageStyle.UNDECORATED – Serafins

15

버튼 코드 아래

관련 문제