0

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?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Pewdut
  • 35
  • 2
  • 9
  • 2
    This could help you: http://stackoverflow.com/questions/1234912/how-to-programmatically-close-a-jframe – Azodious Oct 29 '12 at 12:11

2 Answers2

1

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);
Jemish Patel
  • 444
  • 3
  • 13
  • Sorry but JOptionPane cant even take those arguments? – Pewdut Oct 30 '12 at 07:50
  • posted my own awnser! Your awnser was helpful and pointed me in the right direction but it was not complete since the code you submitted was not correct :) Thank you ! – Pewdut Oct 30 '12 at 08:18
0

The awnser to my question is partly awnserd by you both, but this is the solution wich worked for me!

  JOptionPane pane = new JOptionPane(tempviewAssistChanges, JOptionPane.PLAIN_MESSAGE);
    final JDialog dialogrr = pane.createDialog(frame.getParent(), "Result report");
    dialogrr.setVisible(true);
    final ActionListener action = new ActionListener()
            {
               public void actionPerformed(ActionEvent e)
               {
                  if(loggedout)
                  {
                     dialogrr.dispose();
                  }
               }
            };
Pewdut
  • 35
  • 2
  • 9