Reputation: 51
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]);`
Upvotes: 1
Views: 1267
Reputation: 205885
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.
Upvotes: 1