创建JavaFX对话框 [英] Creating a JavaFX Dialog Box
问题描述
对话框必须停止执行其余的代码,直到响应如是或否或重试。当我使用我的对话框,如DialogBox.ShowMessage,一个阶段出现与消息和按钮。但是,如你所想,代码的其余部分继续执行。我该怎么办?当我创建舞台时,它必须停止其他线程或其所依赖的线程。我通过互联网和这里搜索,但我找不到确切的解决方案。一个想法是使用javafx.event.EventDispatcher或javafx.event.EventDispatchChain,但我无法弄清楚如何使用它们。另一个想法是使用java.awt.EventQueue。这里有一些可以帮助的事情:我可以控制舞台表演和隐藏事件,并显示或隐藏事件处理程序。我认为某种线程队列可以在其中一个spesific部分中使用。
我希望我能够充分了解情况。简单来说,ı需要管理线程,而使用另一个阶段,我自己的代码。
谢谢。
关于执行暂停有一个Jira问题 http: //javafx-jira.kenai.com/browse/RT-19783 。
作为解决方法,我不知道如何使用EventDispatcher和EventDispatchChain来克服此问题,但您可以发送 EventHandler
作为参数。例如,
public static void ShowMessage(final EventHandler< ActionEvent> okAction,final EventHandler< ActionEvent> cancelAction){
//定义并添加按钮到视图并显示消息
btnOk.setOnAction(new EventHandler< ActionEvent>(){
public void handle(ActionEvent event) {
okAction.handle(null);
}
});
btnCancel.setOnAction(new EventHandler< ActionEvent>(){
public void handle(ActionEvent event){
cancelAction.handle(null);
}
});
}
并将其用作
pre>
DialogBox.ShowMessage(
new EventHandler< ActionEvent>(){
@Override public void handle(ActionEvent arg0){
// Do
},
新的EventHandler< ActionEvent>(){
@Override public void handle(ActionEvent arg0){
//在取消 click $。
});
我同意这是一种蜿蜒的方式。
Site ye。。。。。。。。。。。。。。>>>>>>>>
I am coding a javafx program and i need to create and use my own Stage based (Javafx.Stage) dialog box for showing messages and confirmations. I have written all the necessary code by now but i have a problem:
A dialog box must stop execution of rest of the code until a respond is given like "yes" or "no" or "retry". When i use my dialog box like "DialogBox.ShowMessage", a stage appears with message and buttons. But, as you may think, the rest of the code continues to execute. How can i get around this? When i create the stage, it must stop the other threads or the thread that it depends on. I have searched through internet and here, but i can not find exact solution. One idea is using "javafx.event.EventDispatcher" or "javafx.event.EventDispatchChain" but i couldn't figure out how to use them. And another idea is using "java.awt.EventQueue". And here is somthing that can help: I have a control of stage show and hide events and showing or hiding eventhandlers. I think som sort of thread queue can be used in one of these spesific sections.
I hope i clarified the situation enough. Briefly, ı need to manage threads while using another stage with my own code.
Thank you.
About execution suspending there is a Jira issue for it http://javafx-jira.kenai.com/browse/RT-19783.
As a workaround, I have no idea how to use EventDispatcher and EventDispatchChain to overcome this problem but you can send the EventHandler
s as parameter. For instance,
public static void ShowMessage(final EventHandler<ActionEvent> okAction, final EventHandler<ActionEvent> cancelAction){
// Define and add buttons to the "view" and show message
btnOk.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
okAction.handle(null);
}
});
btnCancel.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
cancelAction.handle(null);
}
});
}
and use it as,
DialogBox.ShowMessage(
new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent arg0) {
// Do stuff when "ok" clicked.
},
new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent arg0) {
// Do stuff when "cancel" clicked.
});
I agree with this is a kind of "winding" way however.
Siteye hoş geldin ve kolay gelsin.
这篇关于创建JavaFX对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!