基本上,我需要一个字段(用于 Swing),如果指定的数据不在 Combo-box
中提供的列表中,则允许用户输入数据。如何实现这一目标?
最佳答案
查看 swing tutorial 上的“可编辑组合框” .
基本上,您需要对组合框使用setEditable(true)
。来自 API 文档:
Determines whether the JComboBox field is editable. An editable JComboBox allows the user to type into the field or selected an item from the list to initialize the field, after which it can be edited. (The editing affects only the field, the list item remains intact.) A non editable JComboBox displays the selected item in the field, but the selection cannot be modified.
关于java - 既充当文本字段又充当组合框的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13339129/