javafx,如何实现confirmHandler? [英] javafx, how to implement confirmHandler?

查看:530
本文介绍了javafx,如何实现confirmHandler?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用javafx的webengine来显示网页。在页面上,有脚本调用window.confirm。我已经知道如何设置确认处理程序以及如何显示类似模态的对话框。

I'm using javafx's webengine to display a web page. And on the page, there's script calling window.confirm. I already know how to set the confirm handler and how to show a modal-like dialog.

我的问题是如何在处理程序返回之前获得用户的选择?

My question is how can I get the user's choice before handler returns?

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 ,我们可以使用新方法showAndWait JavaFx 2.2实现此目的。

As described in javafx-jira.kenai.com/browse/RT-19783, we can use the new method showAndWait which is available in JavaFx 2.2 to achieve this.


阶段类:

Stage class:

/** 
 * 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 。谢谢!

@jewelsea created a sample on https://gist.github.com/2992072. Thanks!

这篇关于javafx,如何实现confirmHandler?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆