컨트롤러에서 사용하기 때문에 반환 값을 얻을 수없는 문제가 있습니다. 창을 닫은 후 확인란에서 반환 값을 가져 오는 방법은 무엇입니까? 컨트롤러에 반환 값이 필요하기 때문입니다.javafx 메시지 상자에서 반환 값을 얻는 방법
import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.layout.VBox; import javafx.stage.Modality; import javafx.stage.Stage; public class CheckBox { public static String display(String title, String message){ Stage window = new Stage(); String id = " "; window.initModality(Modality.APPLICATION_MODAL); window.setTitle(title); window.setMinWidth(250); Label label = new Label(); label.setText(message); Button yButton = new Button("Y"); Button nbButton = new Button("N"); yButton.setId("Y"); nbButton.setId("N"); yButton.setOnAction(e -> window.close()); nbButton.setOnAction(e -> window.close()); VBox layout = new VBox(10); layout.getChildren().addAll(label,yButton, nbButton); layout.setAlignment(Pos.CENTER); Scene scene = new Scene(layout); window.setScene(scene); window.showAndWait(); if(yButton.isPressed()) return yButton.getId(); else if(nbButton.isPressed()) return nbButton.getId(); return null; } }
이 대화에서 정확히 무엇을 원하십니까? –
사용자가 Ybutton을 클릭하면 ID 인 Y를 반환하고 @mrmcwolf 컨트롤러에서 문자열 "Y"를 얻고 싶습니다 – JhihweiLi