我试图让位置(作为INT)的选择对象位置,生成组合框和富人这样入门的JComboBox对象的JComboBox
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);
的动作侦听器执行
static private String selectedString(ItemSelectable is) {
Object selected[] = is.getSelectedObjects();
return ((selected.length == 0) ? "null" : (String)selected[0]);
}
但我希望所选对象的位置通过该int从另一个数组获取字符串。
这甚至可能吗?通过我所做的搜索,甚至没有提到这一点。
你能向我解释具体的课吗?不太明白这是什么意思。 在eclipse中,它给了我关闭添加选项(Component comp,Index int)。该组件可以是数组的x位置的字符串吗? – Lucky
“具体类”,我的意思是你可能需要在你的监听器代码中使用'JComboBox'而不是'ItemSelectable'。对于JComboBox, –
会更好看ItemListener,+1 – mKorbel