Java multiple selection dialog box

China☆狼群 提交于 2020-01-24 12:29:08

问题


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.


回答1:


JList is also a good alternative for multiple selections.




回答2:


I would suggest a JTable with 2 columns. The first one is Boolean class based and the second one is text for the boolean.




回答3:


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



来源:https://stackoverflow.com/questions/7565061/java-multiple-selection-dialog-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!