8

How to retrieve Text that is typed in JComboBox. This text need not be an existing item.

3 Answers 3

17

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.

2

Simply use :

String value= comboBox.getSelectedItem().toString();

Other examples available here

0

You can try the following

String typedText = ((JTextField)myComboBox.getEditor().getEditorComponent()).getText();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.