Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve text from JComboBox

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

like image 734
Reddy Avatar asked Aug 16 '10 19:08

Reddy


2 Answers

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.

like image 120
Carlos Avatar answered Oct 24 '22 22:10

Carlos


Simply use :

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

Other examples available here

like image 21
Mehdi Avatar answered Oct 24 '22 23:10

Mehdi