Luc*_*cky 1 java swing jcombobox drop-down-menu
我正在尝试获取JComboBox对象的位置(作为int),生成ComboBox并拥有这样的动作侦听器
for (int d=0; d<i; d++)
{
titulos.addItem(listaPraBox[d]);
}
ActionListener comboListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
ItemSelectable is =(ItemSelectable)actionEvent.getSource();
objectoseleccionado = selectedString(is);
DeskMetodos.listaTexto(objectoseleccionado);
}
};
titulos.addActionListener(comboListener);
Run Code Online (Sandbox Code Playgroud)
执行
static private String selectedString(ItemSelectable is) {
Object selected[] = is.getSelectedObjects();
return ((selected.length == 0) ? "null" : (String)selected[0]);
}
Run Code Online (Sandbox Code Playgroud)
但我希望所选对象的位置通过该int从另一个数组中获取字符串.
这甚至可能吗?通过我所做的搜索,甚至没有提到这一点.
JComboBox定义getSelectedIndex().实现只是循环检查与之相等的数据模型getSelectedItem().
这并没有实现ItemSelectable,但数据模型本身也没有,所以你可能需要使用具体的类.
| 归档时间: |
|
| 查看次数: |
5926 次 |
| 最近记录: |