Retrieve text from JComboBox

Reddy picture Reddy · Aug 16, 2010 · Viewed 35.1k times · Source

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

Answer

Carlos picture Carlos · Aug 16, 2010

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.