1 Reply Latest reply: Apr 30, 2012 4:04 PM by jsmith RSS

    how can I implement a model (DialogResult) window function?

    928280
      //Popup extends Stage,
      Popup popup=new Popup(primaryStage,title,content);
      DialogResult result=popup.show();
      
      if(result==DialogResult.ok)//if user doesn't close stage, this line isn't triggered.
      {
         //my next code here...
      }
        public enum DialogResult
          {
               OK,
               Cancel,
               Yes,
               No,
               None
          } 
      Actually,I implemented Popup based on Stage, and I created a lot of customized control in popup,I'd like to wait for the Dialogresult value if user do something on my popup,if user doesn't close stage, if(result==DialogResult.ok) isn't triggered.any suggestion?

      Edited by: imtoocute on Apr 30, 2012 1:41 PM
        • 1. Re: how can I implement a model (DialogResult) window function?
          jsmith
          This has got to be one of the most asked questions on the forum - I guess because (with the exception of JavaFX 2.0), every UI technology known to man has had this functionality built-in since their first version.

          There are a few different ways to achieve this:
          See:
          Dialog Box Problem "Dialog Box Problem"
          https://gist.github.com/1887631 "     JavaFX Modal Confirm Dialog Box Example"
          http://javafx-jira.kenai.com/browse/RT-19783 "Provide an option to allow modal windows to be blocking" (implemented for 2.2)
          http://javafx-jira.kenai.com/browse/RT-12643 "Add javafx.scene.control.Alert class"
          Quick answer is that unless you are using 2.2 and can use a stage.showAndWait() function, then implement your dialog via a stage or a popup or a stackpane overlay and use callbacks on actions in the dialog to collect the result of user interaction with the dialog and resume execution.
          Hopefully that helps you.