Java Dialog - Find out if OK is clicked?

前端 未结 4 1672
一向
一向 2020-12-01 22:48

I have a dialog for a client-GUI that asks for the IP and Port of the server one wants to connect to. I have everything else, but how would I make it so that when the user c

4条回答
  •  甜味超标
    2020-12-01 23:16

    Good solutions. If you want not to use something else, this is a working example: 1) set DO_NOTHING_ON_CLOSE to ensure user MUST press OK 2) verify if the JDialog is still visible.

    dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dialog.setModal(false);
    dialog.setVisible(true);
    dialog.setAlwaysOnTop(true);
    while(dialog.isVisible())try{Thread.sleep(50);}
    catch(InterruptedException e){}
    

    This can be a solution if you want to implement a non-modal dialog box.

提交回复
热议问题