gpt4 book ai didi

java - 如何编写自定义 JOptionPane 按钮?

转载 作者:太空宇宙 更新时间:2023-11-04 07:47:27 25 4
gpt4 key购买 nike

我有一些关于 JOptionPane 类的问题。为什么JOptionPane自定义按钮默认退出?例如,如果我单击“清除”,为什么程序会关闭而不清除文本字段并保持静止?另外,如果我单击“向文件添加数据或从文件检索数据”,为什么程序会关闭?为什么它们不像框架上的 JButton 那样使用react?

您能否向我展示一个如何在不关闭窗口的情况下清除或转到上一个表单的示例。

代码:

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]);`

最佳答案

您可能对教程文章 Stopping Automatic Dialog Closing 感兴趣,它说明了如何使用 PropertyChangeListener 来覆盖默认行为。这个JOptionTimeTest是一个相关的例子。

关于java - 如何编写自定义 JOptionPane 按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15057828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com