2

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?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
special
  • 621
  • 3
  • 11
  • 20

3 Answers3

8

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

Howard
  • 38,639
  • 9
  • 64
  • 83
4

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...

Federico Vera
  • 1,357
  • 1
  • 12
  • 18
1

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

zip
  • 579
  • 1
  • 3
  • 16