Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何检索在 JComboBox 中键入的文本。此文本不必是现有项目。
您可以通过调用方法从 JComboBox 中获取选定或键入的值getSelectedItem。如果它不是现有项目,那么您将获得一个 String 对象。否则,您将获得填充组合框的任何对象。
getSelectedItem
只需使用:
String value= comboBox.getSelectedItem().toString();
此处提供的其他示例
您可以尝试以下方法
String typedText = ((JTextField)myComboBox.getEditor().getEditorComponent()).getText();