Skip to content
Advertisement

How to terminate a JOptionPane ConfirmDialog from an actionListener

I use this line to show my ConfirmDialog

int yn = JOptionPane.showConfirmDialog(frame.getParent(), scrollPane, "stuffs",
         JOptionPane.OK_CANCEL_OPTION);

In that ConfirmDialog I have a button which calls a server using a actionListener, when the connection is broken I have a check which terminates the function. But i can for the love of god not figure out how to terminate the ConfirmDialog at the same time.

How can I solve this problem while still using ConfirmDialog?

Advertisement

Answer

You could use setVisible(false) or dispose() method

JOptionPane pane=newJOptionPane(frame.getParent(),scrollPane,"stuffs",JOptionPane.OK_CANCEL_OPTION);
pane.dispose(); //or pane.setVisible(false);
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement