开发者

How exactly does the modal variable in Java Dialogs work?

In the JavaDocs for Dialog(Dialog,String,modal) it says the following:

modal - if true, dialog blocks input to other app windows when shown

If I understand correctly, if I pass a true argument to the constructor of a Dialog, will it just pause all the program until the user gives some kind of input to the application using this dialog?

For example suppose that we have this function in a class and a JDialog called test.

 public void function(){

  /*line*/   test t = new test(null, true); 

             while(true){
             System.out.println("print stuff");
        }
     }

If I call this function, it will pause, at line, then since the initial dialog is empty, if for example I close the dialog, then the while loop will be executed.

Is the phrase "the program pauses until the user gives an input 开发者_JAVA百科using the dialog" is a somewhat correct description of what the modal variable is useful for?


Its partially correct, but.

But it isn't enough to call teh constructor, but you need to show the dialog after the constructor like this:

t.setVisible(true);

and yes, after this, the while loop does not start till the dialog isn't closed ( setVisible(false) )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜