有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java更新JCombobox总是让第一个元素为空

我没有选择使用此方法来更新JCombobox,它包括:

update() {
    faultySection.removeAllItems();
    int idx = 1;
    faultySection.insertItemAt(select, 0);

    for (Incident i : listeIncidents) {
        faultySection.insertItemAt(object, idx++);
    }
}

但是我得到的是第一个元素(默认元素)仍然是空的,而不是select

The default object is empty in the JCombobox

Have a look at the content of the list


共 (2) 个答案

  1. # 1 楼答案

    试试这个:

    faultySection.insertItemAt("select", 0);
    faultySection.setSelectedIndex(0);
    
  2. # 2 楼答案

    在我看来,这在功能上是正确的。在此方法中放置调试器断点,并在处理faultySection时监视其状态。你可以把它添加到观察声明中,这样你的工作就容易多了。我认为必须有其他代码在另一个语句中修改它