Ich brauche den Integer-Wert der Combobox in Swing.Erhalten Combobox Wert in Java Swing
Ich habe einen Integer-Wert als ID für die Combobox gesetzt. Ich habe versucht, combobox.getSelectedItem() und combobox.getSelectedIndex(), aber es kann nicht den int-Wert.
Unten ist mein Code:
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;
}
Jede Hilfe sehr geschätzt wird.
Also, wie hast du es eingestellt? – nullpotent
Bitte geben Sie [SSCCE] (http://sscce.org/) ein, das das Problem veranschaulicht. – tenorsax
Ihr Update ist unvollständig. Was ist zum Beispiel der Typ von projectId? – trashgod