这是要点,我有一个由字符串数组填充的下拉菜单。 当我从该菜单中选择一个项目时,我希望它在数组中的位置而不是它的字符串值。
我的意思是here.
的屏幕截图和 这是代码:
case "Sell product" :
ArrayList <Order> Sell_list = db.getList();//call database get list.
int Sell_length = Sell_list.size();//sentinel
if (Sell_length == 0){
JOptionPane.showMessageDialog(null, "There are no items to be sold.");
break;
}
String[] options = new String[Sell_length];
for (int iterator=0; iterator<Sell_length; iterator++) {
Order orderAnalized = Sell_list.get(iterator);
Product productAnalized = orderAnalized.getProduct();
options[iterator] = productAnalized.getName();
}
int chosen = (int)JOptionPane.showInputDialog(null,
"Please Select product to sell",
"Selling Product Menu",
JOptionPane.QUESTION_MESSAGE,
null, options, options[0]
);
JOptionPane.showMessageDialog(null, chosen);
break;