Retrieve text from JComboBox
Asked Answered
K

3

9

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

Kurtz answered 16/8, 2010 at 19:21 Comment(0)
G
18

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.

Gabriellegabrielli answered 16/8, 2010 at 19:27 Comment(0)
C
3

Simply use :

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

Other examples available here

Confirmatory answered 3/11, 2017 at 17:36 Comment(0)
S
0

You can try the following

String typedText = ((JTextField)myComboBox.getEditor().getEditorComponent()).getText();
Skewback answered 7/3, 2020 at 4:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.