关于JOptionPane
课,我有几个问题。为什么JOptionPane
自定义按钮默认退出?例如,如果我点击清除,为什么程序关闭而不清除文本字段并保持静止?此外,如果我点击添加或从文件中检索数据,为什么程序关闭?为什么他们不像帧JButtons
那样反应?
请您告诉我一个如何在没有关闭窗口的情况下清除或转到上一个表单的示例。
代码:
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]);`
答案 0 :(得分:1)
您可能对教程文章Stopping Automatic Dialog Closing感兴趣,该文章说明使用PropertyChangeListener
覆盖默认行为。这个JOptionTimeTest
是一个相关的例子。