Language/JavaFX

fxml의 button에서 다른 fxml 띄우기

아르비스 2015. 10. 14. 20:12

java fxml button event 생성 후


button method에서 



1) 모달로 띄우기

void onAuthCodeGrantClick(ActionEvent event) {

        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/AuthenticationCode.fxml"));

        Parent root1;

        Stage stage;

        try {

            root1 = (Parent) fxmlLoader.load();

            stage = new Stage();

            stage.initModality(Modality.APPLICATION_MODAL);

            stage.initStyle(StageStyle.UNDECORATED);

            stage.setTitle("ABC");

            stage.setScene(new Scene(root1));  

            stage.show();

        } catch (IOException ex) {

            Logger.getLogger(JanusAgentController.class.getName()).log(Level.SEVERE, null, ex);

        }

    }



2) 윈도우로 띄우기 (프레임)

try {

        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/AuthenticationCode.fxml"));

                Parent root1 = (Parent) fxmlLoader.load();

                Stage stage = new Stage();

                stage.setScene(new Scene(root1));

                stage.setTitle("Authentication Code Grant");

                stage.show();

        } catch(Exception e) {

           e.printStackTrace();

        }