gpt4 book ai didi

java - 自动在jcombobox中显示所选项目

转载 作者:行者123 更新时间:2023-12-01 05:28:21 28 4
gpt4 key购买 nike

我已经完成从 MySQL 到 JComboBox 的数据检索。成功了。

  1. 初始 enter image description here
  2. 我选择类别“其他”而不是“成分”,然后保存。 enter image description here
  3. 但是当我使用搜索按钮时,类别显示“成分”而不是“其他”。我的问题是我想显示其他(或我选择的任何类别) enter image description here

如果此代码将检索我在字段中的数据:

inventCodeField.setText(rs.getString("ItemCode"));

如何检索我从 JComboBox 中选择的数据而不删除其他选择?

最佳答案

查询到具体记录后,提取category的字段值,然后将其作为JComboBox类的setSelectedItem()的参数。

// assume that category is a String that holds the category value after querying
cbo_category.setSelectedItem(category);

关于java - 自动在jcombobox中显示所选项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9426034/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com