[英]How can I populate a combo box with values of an enum in NetBeans GUI editor?
[英]How can i add items to java text file through GUI combo box(netbeans)
我已經在gui的組合框中定義了項目。 發生的情況是,我試圖在程序文本文件中添加一個條目,它說:不兼容的類型int無法轉換為字符串。 我在setLocation
和setSkills
方面遇到問題。
private void buttonAddActionPerformed(java.awt.event.ActionEvent evt)
{
Resort p = new Resort();
p.setName(nameTextField.getText().replaceAll("[^a-z.]", ""));
p.setLocation(comboResortLocation.getSelectedIndex());
p.setSkillsByIndex(comboResortSkill.getSelectedIndex());
txtfile.addResort(p);
AddedConfirm confirmed = new AddedConfirm();
confirmed.setVisible(true);
this.setVisible(false);
}
以及部分代碼來自另一個文件。
public void setSkillsByIndex (String skills)
{
this.skills = skills;
}
已經解決了。 我只需要將它們更改為Strings,而是使用getSelectedItem:
p.setLocationByIndex((String) comboResortLocation.getSelectedItem());
p.setSkillsByIndex((String) comboResortSkill.getSelectedItem());
和另一個文件:
public void setLocationByIndex(字符串位置){this.location = location;
}
public void setSkillsByIndex(字符串技能){this.skills =技能;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.