View Full Version : simple Java question about comboboxes

August 2nd, 2011, 05:23 PM
Hey there, I just want to know how to add an item from the combo box's text.

For example, lets say the program just has a combobox ad nothing more on the screen, the user types in the combobox, and then hits enter and then the text the user typed gets added into the combobox its self. The code for hitting enter is not important here.

It seems like the code should be this.jCombobox1.addItem(this.jCombobox1.getText);
but obviously it isnt.

How would I do this? I really dont want to have to have an editable combobox AND a textfield...

August 2nd, 2011, 07:16 PM
You need to get the item through the editor of the JComboBox:

Object item = comboBox.getEditor().getItem();

August 3rd, 2011, 09:45 AM
EDIT: Never mind.