Get input values from JComboBox

╄→гoц情女王★ 提交于 2019-11-29 16:08:36

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

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

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

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