本文介绍了有没有办法在JOptionPane showInputDialog中只有OK按钮(而且没有CANCEL按钮)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经看到这可以在其他类型的对话框窗口中使用,例如showConfirmDialog,其中可以指定按钮的数量及其名称;但使用showInputDialog时是否可以实现相同的功能?我似乎无法在API中找到这种类型的东西。也许我只是错过了它,但感谢任何帮助。
I've seen that this is possible in other types of dialog windows such as "showConfirmDialog", where one can specify the amount of buttons and their names; but is this same functionality achievable when using "showInputDialog"? I couldn't seem to find this type of thing in the API. Perhaps I just missed it, but any help is appreciated.
推荐答案
只需将自定义JPanel添加为 JOptionPane.showOptionDialog()
:
Just add a custom JPanel as a message to JOptionPane.showOptionDialog()
:
String[] options = {"OK"};
JPanel panel = new JPanel();
JLabel lbl = new JLabel("Enter Your name: ");
JTextField txt = new JTextField(10);
panel.add(lbl);
panel.add(txt);
int selectedOption = JOptionPane.showOptionDialog(null, panel, "The Title", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]);
if(selectedOption == 0)
{
String text = txt.getText();
// ...
}
这篇关于有没有办法在JOptionPane showInputDialog中只有OK按钮(而且没有CANCEL按钮)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!