Win a copy of Java by Comparison (eBook) this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JOptionPane.showInputDialog with a list  RSS feed

Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When numberOfAlternatives is 19 JOptionPane allows only one row to be selected in the JComboBox. If numberOfAlternatives is 20 you can choose multiple rows in JList. Can someone tell why this happens and how can I allow only one selection? Of course I can write my own class for a dialog, but is it possible to use JOptionPane in this situation?
Object[] possibleValues = new String[maxSeats];
int numberOfAlternatives = 19;
for (int i = 1; i <= numberOfAlternatives; i++) {
possibleValues[i-1] = new String(new Integer(i).toString());
Object selectedValue = JOptionPane.showInputDialog(null,
"Choose a number", "Choose",
JOptionPane.PLAIN_MESSAGE, null, possibleValues,
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!