Ho bisogno di ottenere il valore intero della casella combinata in Swing.Ottieni valore combobox in swing Java
Ho impostato un valore intero come id per la casella combinata.Ho provato combobox.getSelectedItem() e combobox.getSelectedIndex() ma non è possibile ottenere il valore int.
Qui di seguito è il mio codice:
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;
}
Ogni aiuto è apprezzato.
Quindi, come l'hai impostato? – nullpotent
Si prega di inviare [SSCCE] (http://sscce.org/) che dimostra il problema. – tenorsax
L'aggiornamento è incompleto. Qual è il tipo di 'projectId', ad esempio? – trashgod