I used
JOptionPane.showOptionDialog(null, new MyPanel(), "Import", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, new Object[]{}, null);
because I don't want the default buttons provided by the OptionDialog and I created my buttons inside the MyPanel extends JPanel
So my problem is now how can I close that OptionDialog from inside the MyPanel
fired by an ActionEvent
? I don't care the return value, as long as that dialog disappears. And I realize this might not be the best design but I've been working on this for a lot of times so I'd prefer a fix that involves as little change in the structure as possible. Thanks!
Convert
JOptionPane
to aJDialog
, using JOptionPane.createDialog(String title) :Now inside the
actionPerformed(ActionEvent ae)
method, simply write :Have a look at this working example :