'대화창'에 해당되는 글 1건

  1. 2016.09.30 javafx로 대화창/경고창 생성하기

  JavaFX 8u40 버전에 간단한 대화창/경고창 클래스들이 추가되었다.(참조) 예를 들어 경고창은 다음과 같이 간단히 생성할 수 있다.


Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("Warning Dialog");
alert.setHeaderText("Look, a Warning Dialog");
alert.setContentText("Careful with the next step!");

alert.showAndWait();


동일한 Alert객체로 확인창도 생성할 수 있다.


Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Confirmation Dialog");
alert.setHeaderText("Look, a Confirmation Dialog");
alert.setContentText("Are you ok with this?");

Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK){
   // ... user chose OK
} else {
   // ... user chose CANCEL or closed the dialog
}


또는 간단한 문자열 입력기도 다음과 같이 간단히 생성하여 문자열을 입력받아 후처리를 할 수 있다.


TextInputDialog dialog = new TextInputDialog("walter");
dialog.setTitle("Text Input Dialog");
dialog.setHeaderText("Look, a Text Input Dialog");
dialog.setContentText("Please enter your name:");

result.ifPresent(name -> System.out.println("Your name: " + name));


 이전에는 이런 간단한 기능도 별도로 구현하기가 까다로웠는데 이제는 쉽게 할 수 있다.

n{espy}n{005}


Posted by 살레시오
,