1

我正在使用 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?
}
});
4

1 回答 1

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上创建了一个示例。谢谢!

于 2012-06-26T02:11:47.343 回答