Java多选对话框

发布于 2024-12-06 13:18:15 字数 741 浏览 1 评论 0原文

我有一个带有如下下拉菜单的对话框:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

記憶穿過時間隧道 2024-12-13 13:18:15

JList 也是一个不错的选择用于多项选择。

JList is also a good alternative for multiple selections.

有深☉意 2024-12-13 13:18:15

我建议使用包含 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.

不交电费瞎发啥光 2024-12-13 13:18:15

您可能需要 JCheckBox 或 JRadioButton 教程显示类似示例你 ...

you probably needed JCheckBox or JRadioButton tutorial shows similair example as you ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文