Java多选对话框
我有一个带有如下下拉菜单的对话框:
Object[] possibilities = {"1", "2", "3", "4"};
ImageIcon icon = new ImageIcon("images/middle.gif");
int i = Integer.parseInt((String)JOptionPane.showInputDialog(pane,"How Many Channels:","Reset Visible Channels",
JOptionPane.PLAIN_MESSAGE,icon,possibilities,"1"));
问题是它只允许您选择一个选项。相反,我想 让用户能够从给出的列表中选择多个选项 对话框。类似以下内容:
Object[] possibilities = {"apples", "oranges", "lemons", "grapes"};
ImageIcon icon = new ImageIcon("images/middle.gif");
String s = (String)what do i put here instead of JOptionPane.showInputDialog(); ?
任何人都可以告诉我如何更改此代码,以便它执行我所要求的操作吗?
很高兴知道我的各种格式选项是什么。我真的很感激任何有关该主题的好文章的链接。我从谷歌搜索中找到的文章信息量不大。我可能使用了错误的关键词。
I have a dialog box with a drop down menu like this:
Object[] possibilities = {"1", "2", "3", "4"};
ImageIcon icon = new ImageIcon("images/middle.gif");
int i = Integer.parseInt((String)JOptionPane.showInputDialog(pane,"How Many Channels:","Reset Visible Channels",
JOptionPane.PLAIN_MESSAGE,icon,possibilities,"1"));
The problem is that it only lets you select one option. Instead, I would like
for users to be able to select multiple options from a list that is given in
the dialog box. Something like the following:
Object[] possibilities = {"apples", "oranges", "lemons", "grapes"};
ImageIcon icon = new ImageIcon("images/middle.gif");
String s = (String)what do i put here instead of JOptionPane.showInputDialog(); ?
Can anyone show me how to alter this code so that it does what I am asking?
It would be nice to know what some of my various format options are. And I would really appreciate any links to some good articles on the topic. The articles I have found from my google searches are not very informative. I might be using the wrong key words.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
JList
也是一个不错的选择用于多项选择。JList
is also a good alternative for multiple selections.我建议使用包含 2 列的 JTable。第一个是基于布尔类的,第二个是布尔值的文本。
I would suggest a JTable with 2 columns. The first one is Boolean class based and the second one is text for the boolean.
您可能需要 JCheckBox 或 JRadioButton 教程显示类似示例你 ...
you probably needed JCheckBox or JRadioButton tutorial shows similair example as you ...