我使用javafx的webengine来显示网页。在页面上,有脚本调用window.confirm。我已经知道如何设置确认处理程序以及如何显示类似模态的对话框。
我的问题是如何在处理程序返回之前获得用户的选择?
webEngine.setConfirmHandler(new Callback<String, Boolean>() {
@Override
public Boolean call(String message) {
// Show the dialog
...
return true; // How can I get user's choice here?
}
});
答案 0 :(得分:3)
如javafx-jira.kenai.com/browse/RT-19783中所述,我们可以使用JavaFx 2.2中提供的新方法showAndWait来实现此目的。
舞台课程:
/** * Show the stage and wait for it to be closed before returning to the * caller. This must be called on the FX Application thread. The stage * must not already be visible prior to calling this method. This must not * be called on the primary stage. * * @throws IllegalStateException if this method is called on a thread * other than the JavaFX Application Thread. * @throws IllegalStateException if this method is called on the * primary stage. * @throws IllegalStateException if this stage is already showing. */ public void showAndWait();
@jewelsea在https://gist.github.com/2992072上创建了一个示例。谢谢!