在 Java swing 中获取组合框值
我需要在Swing中获取组合框的整数值。
我已将整数值设置为组合框的id。我尝试了combobox.getSelectedItem()和combobox.getSelectedIndex(),但它无法获得int值。
以下是我的代码:
CommonBean commonBean[]=new CommonBean[commonResponse.getCommonBean().length+1];
for(int i=0;i<commonResponse.getCommonBean().length;i++)
{
commonBean[i] = new CommonBean("--Please select a project--", 0);
commonBean[i+1] = new CommonBean(commonResponse.getCommonBean()[i].getProjectName(), commonResponse.getCommonBean()[i].getProjectId());
}
JComboBox combobox= new JComboBox(commonBean);
public CommonBean(String projectName,int projectId) {
this.projectName = projectName;
this.projectId = projectId;
}
任何帮助是值得赞赏的。