Tôi cần lấy giá trị nguyên của combobox trong Swing.Nhận giá trị combobox trong Java swing
Tôi đã đặt giá trị số nguyên làm id cho combobox.I đã thử combobox.getSelectedItem() và combobox.getSelectedIndex() nhưng không thể nhận giá trị int.
Dưới đây là mã của tôi:
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;
}
Any help is appreciated.
Vì vậy, bạn đã đặt nó như thế nào? – nullpotent
Vui lòng đăng [SSCCE] (http://sscce.org/) để minh họa sự cố. – tenorsax
Bản cập nhật của bạn chưa hoàn tất. Ví dụ, loại 'projectId' là gì? – trashgod