我正在研究JavaFX应用程序,在我的场景中是显示在JavaFX中创建的密码提示,它带有两个选项的密码OK和Cancel.我已经返回了用户输入的密码.
我的密码对话框是 -
public static String showPasswordDialog(String title, String message, Stage parentStage, double w, double h) {
try {
Stage stage = new Stage();
PasswordDialogController controller = (PasswordDialogController) Utility.replaceScene("Password.fxml", stage);
passwordDialogController.init(stage, message, "/images/password.png");
if (parentStage != null) {
stage.initOwner(parentStage);
}
stage.initModality(Modality.WINDOW_MODAL);
stage.initStyle(StageStyle.UTILITY);
stage.setResizable(false);
stage.setWidth(w);
stage.setHeight(h);
stage.showAndWait();
return controller.getPassword();
} catch (Exception ex) {
return null;
}
Run Code Online (Sandbox Code Playgroud)
我的代码显示密码提示的位置如下,实际上这个提示将显示在其他UI上,所以我需要将其包含在内部Platform.runlater(),否则它会抛出Not on FX application thread.我需要这个密码提示才能显示,直到我得到正确的密码提示.如果我在runlater中显示密码,我怎样才能获得密码值.
还有其他更好的方法吗?
final String sPassword = null;
do {
Platform.runLater(new Runnable() { …Run Code Online (Sandbox Code Playgroud)