gpt4 book ai didi

java - 自定义 JOptionPane 覆盖 YES_NO_CANCEL 按钮时获取 "Cancel"操作

转载 作者:行者123 更新时间:2023-12-01 04:32:33 28 4
gpt4 key购买 nike

我在尝试弄清楚如何检查用户是否按下自定义 JOptionPane 中的按钮时遇到一个小问题。

我的对话框基于 inputDialog,其中包含用于 YES、NO 和 CANCEL 按钮(“选择”、“取消”、“打开编辑器”)的自定义文本。

我尝试寻找解决方案,但我发现的只是使用静态 JOptionPane 函数的问题。

这是我现在使用的代码:

public SelectItemDialog(Component parent) {
super("Please select an item:", YES_NO_CANCEL_OPTION, PLAIN_MESSAGE, Editor.getIcon("bookmark"),
new String[] { "Select", "Cancel", "Open Item Editor" }, "Select"
);

setWantsInput(true);

setSelectionValues(null); // Would replace with an Object array
setInitialSelectionValue(null);

setComponentOrientation(getRootFrame().getComponentOrientation());

JDialog dialog = createDialog(parent, "Select Item");
selectInitialValue();

dialog.setVisible(true);
dialog.dispose();

Object obj = getInputValue();

if(obj instanceof Item) {
this.openEditor = false;
this.item = (Item) obj;

} else {
this.openEditor = (obj.equals( CANCEL_OPTION));
this.item = null;
}
}

对 CANCEL_OPTION 的检查根本不起作用,与 UNDEFINED_OPTION 相同。

有什么想法吗?

最佳答案

实际上我只需要使用 JOptionPane 本身返回的对象:getValue(),问题就解决了!

关于java - 自定义 JOptionPane 覆盖 YES_NO_CANCEL 按钮时获取 "Cancel"操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17839721/

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