Get input values from JComboBox

可紊 提交于 2019-11-28 09:49:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!