问题
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?
回答1:
You need to get the edited text from the combobox editor via combo.getEditor().getItem().
回答2:
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
...
回答3:
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
来源:https://stackoverflow.com/questions/10072335/get-input-values-from-jcombobox