Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get input values from JComboBox

How can I get the input for an editable JComboBox. When user gives an input to the combo how I can get the input text from it?

like image 790
special Avatar asked Mar 19 '26 21:03

special


2 Answers

You need to get the edited text from the combobox editor via combo.getEditor().getItem().

like image 164
Howard Avatar answered Mar 21 '26 09:03

Howard


If you need the text that is selected on a JComboBox and you are sure it's a String and not any other object, just use something like String text = (String)myCombobox.getSelectedItem(). If the thing you have in your Model is other than a String, then you need to cast it to the appropriate class, and then use the toString() method of that object. If you need more help, you should paste a bit of your code, at least declaration and inicialization of your JComboBox...

like image 24
Federico Vera Avatar answered Mar 21 '26 10:03

Federico Vera