0

I am trying to find a way to close the window after clicking the JButtons. The OptionDialog doesn't close after I click. Here's what I have so far:

JButton[] option = new JButton[2];
option[0] = new JButton("X"); option[0].addActionListener(this);
option[1] = new JButton("O"); option[1].addActionListener(this);
JOptionPane.showOptionDialog(null, "Please choose!", "", 0, JOptionPane.DEFAULT_OPTION, null, option, null);

What could be a good approach for this?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Alex
  • 3
  • 2
  • This is not how you use the JOptionPane.showOptionDialog. Pass in a String array for the option parameter and then use the result returned to decide what to do. – Hovercraft Full Of Eels Dec 11 '21 at 21:29
  • As for the dialog not closing, best for you to post a valid [mre] so that we can reproduce the problem in simple, easy to copy and test code. Please read the link. – Hovercraft Full Of Eels Dec 11 '21 at 21:33
  • Read the section from the Swing tutorial on [Customizing Button Text](https://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html#button) for an example of how to provide text to be used for the buttons. Keep a link to the tutorial handy for all Swing basics. – camickr Dec 12 '21 at 00:26

0 Answers0