0

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.

Numan Karaaslan
  • 1,365
  • 1
  • 17
  • 25

1 Answers1

1

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 EventHandlers 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.

Community
  • 1
  • 1
Uluk Biy
  • 48,655
  • 13
  • 146
  • 153
  • Thanks for tip. Let me explain again according to your respond. The example link that you have given is emphasizing the Application Modality which is i have already done. That example is blocking the interface NOT CODE. This is my problem. I use is twice and the second message appears without waiting the first one to close. In other words, the second stage is being shown before the first stage is closed. As i understand, your event handler recommendation is about ok or cancel button stuff. i have already done it. I am calling the window, it blocks the interface but NOT THE CODE. Teşekkürler. – Numan Karaaslan Apr 27 '12 at 10:46
  • The issue reporter's attached example **is** about execution (code) blocking after the sub stage is shown. Consider to read that carefully. Similar question exists here [http://stackoverflow.com/q/10008377/682495](http://stackoverflow.com/q/10008377/682495). – Uluk Biy Apr 27 '12 at 11:10
  • Although the issue reporter talking about the `Modality`, there the modality is just about main-sub window ie. interface relations. But the code execution continues with `label.setText("I am not blocking!");` – Uluk Biy Apr 27 '12 at 11:13
  • Oh, now i understand what does "ISSUE" mean. Thank you again. – Numan Karaaslan Apr 27 '12 at 11:48