• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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,
possibleValues[0]);
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!