Get input values ​​from JComboBox

How to get input for editable JComboBox . When a user enters a combo, how can I get input from him?

+2
java swing jcombobox
source share
3 answers

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

+7
source share

If you need the text that is selected on the JComboBox , and you are sure that it is a String , not some other object, just use something like String text = (String)myCombobox.getSelectedItem() . If the thing you have in the Model is different from String , you need to pass it to the appropriate class, and then use the toString() method of this object. If you need more help, you should embed a little of your code, at least the declaration and commissioning of your JComboBox ...

+4
source share

Just take a look at the oracle textbook. They explain how to handle common swing components http://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html

+1
source share

All Articles