1

I have a few questions regarding JOptionPane class. Why does the JOptionPane custom buttons quit by default? For example, if i click on clear, why does the program close and not clear the textfield and stay still? Also, if i click on add or retrieve data to/from file, why does the program closes? Why don't they react like JButtons on a frame?

Could you please show me an example of how to clear or go to previous form without the window closing down.

Code:

String[] buttons = new String[] {"Add", "Clear", "Previous Window", "Retrieve"};
int example = JOptionPane.showOptionDialog(mypanel, mypanel, "Choose", 
    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
    null, buttons , buttons [0]);`
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Ramal
  • 51
  • 2
  • 10

1 Answers1

1

You may be interested in the tutorial article Stopping Automatic Dialog Closing, which illustrates using a PropertyChangeListener to override the default behavior. This JOptionTimeTest is a related example.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045