i want to create a JComboBox
that have a three items on it.. I want to set editable only to the last item of the JComboBox
for example:
JComboBox cb = new JComboBox();
cb.addItem("Dog");
cb.addItem("Cat");
cb.addItem("Other");
when i drop down the JComboBox
and choose the item Others..JComboBox
became editable.. how can I do that?
Here is a demo (not by me) which seems to achieve what you're after. http://raginggoblin.wordpress.com/2010/05/04/jcombobox-with-disabled-items/
You can use an ItemListener to know which item is selected and then you can set the
JComboBox
editable as needed. Try this example:As you'll see, when "Other" item is selected
JComboBox
becomes editable: