Reputation: 1628
How to retrieve Text that is typed in JComboBox. This text need not be an existing item.
Upvotes: 9
Views: 49380
Reputation: 1
You can try the following
String typedText = ((JTextField)myComboBox.getEditor().getEditorComponent()).getText();
Upvotes: 0
Reputation: 1477
Simply use :
String value= comboBox.getSelectedItem().toString();
Other examples available here
Upvotes: 3
Reputation: 2513
You can get the selected or typed value from a JComboBox by calling method getSelectedItem
. If it is not an existing item, then you'll get a String object. Otherwise you'll get whatever object you populated the combo box with.
Upvotes: 18