gpt4 book ai didi

java - JComboBox 不显示结果

转载 作者:行者123 更新时间:2023-12-02 00:47:38 25 4
gpt4 key购买 nike

我试图在数组列表上基于 for 和 if 循环设置 JCombobox 中的值。

     //salesman=the name of the combobox
salesman = new javax.swing.JComboBox();

DefaultComboBoxModel model = new DefaultComboBoxModel();
salesman.setModel(model);

/*company is an object of Company class, that gets set with a setter method to ensure
that the gui will be pointing to the right object. and it does contains the data i want, so
i am sure that company is not the problem */
//loop tp set box list
for (Employee current : company.getArray()){

if (current instanceof Salesman) {
salesman.addItem(current.getCode());
}

}

但组合框仍为空。这是为什么?

最佳答案

无论如何,我建议您执行以下操作:

  1. 覆盖 Salesman 类的 toString() 方法以获得所需的视觉表示(即代码)。

  2. 将销售人员而不是代码添加到组合框模型

关于java - JComboBox 不显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4482994/

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