我正在使用 javafx 的网络引擎来显示网页。在页面上,有一个脚本调用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?
}
});
如中所述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。谢谢!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)