java - 既充当文本字段又充当组合框的字段

标签 java swing user-interface jcombobox jtextfield

基本上,我需要一个字段(用于 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/

相关文章:

java - 通过预先存在的 Socket 路由 Http(s)URLConnection

java - 如何检测 JComboBox 中选定的对象?

java - 将组件添加到 jscrollpane 中的面板后如何从下到上滚动

user-interface - 如何在 Web 应用程序中维护状态——因为 HTTP 是无状态的

iphone - 如何在 NavigationController 工具栏中(如邮件应用程序)放置进度条?

java - 与 Swing : Wait for the UI 同步

java - JSF:嵌套 ui:repeat 中的值绑定(bind)

java - 读取日期和时间异常

Java Android WebRTC提供创建抛出错误和Ice Gathering或trickling没有发生

java - 根据数组创建对象