CodeMed
CodeMed

Reputation: 9191

Java multiple selection dialog box

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.

Upvotes: 2

Views: 7997

Answers (3)

trashgod
trashgod

Reputation: 205785

JList is also a good alternative for multiple selections.

Upvotes: 5

StanislavL
StanislavL

Reputation: 57381

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

Upvotes: 4

mKorbel
mKorbel

Reputation: 109813

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

Upvotes: 3

Related Questions