重複の可能性:
Javaのコンボボックスにキーを割り当てます
JComboBox
Swingアプリケーションでコントロールを使用しています。従業員コードと彼の名前を追加するJComboBox
必要がありますが、コードではなく従業員名のみを表示したいと思います。
しかし、従業員名を選択すると、対応する従業員コードが返されます。そのための最良かつ簡単な解決策は何ですか。アイテムを追加するために次のコードを使用していますJComboBox
try
{
JComboBox jc1= new JComboBox();
jc1.addItem("X");
jc1.addItem("Y");
jc1.addItem("Z");
}
public void itemStateChanged(ItemEvent ie)
{
String code=(String)jc1.getSelectedItem();
//while items being selected it should return the emp code of the given emp name
//eg if user selects X it should return the emp code corresponding to X.
}