Issue
I have a JComboBox
which contains some employee ID numbers (which are integer values).
I want to set 'Select employee' to the JComboBox as a default value. As this value is in string format its throwing me an exception like "java.lang.NumberFormatException: For input string: "Select Employee"". How do I do this?
My code is:
public void clear()
{
cmb_emp_id.setSelectedItem("Select Employee");
txt_emp_name.setText("");
txt_department.setText("");
txt_designation.setText("");
joining_date.setDate(new Date());
resign_date.setDate(new Date());
txt_description.setText("");
}
How can I accomplish this?
Solution
It's hard to tell exactly what you're after, especially since you're talking about a number format exception.
However, to reset a JComboBox
to it's original selection, you simply do
cmb_emp_id.setSelectedIndex(0);
Answered By - aioobe
Answer Checked By - Marie Seifert (JavaFixing Admin)