0

我有一个名为 conditionList 的 ArrayList,它存储条件名称。每当添加/编辑或删除一个时,我的 GUI 上的列表更新没有问题。

您可以在下面看到我使用 2 个模型……一个名为 condListModel 的 DefaultListModel 和一个名为 conditionModel 的 DefaultComboBoxModel。

我下面的代码是用于方法 editCondition(),在这个阶段文本已经在 GUI 上更改并且正在这里提交。在我的 GUI 上,在我提交更改后,ComboBox 和 JList 更改没有问题,所以我确定模型更改是正确的。

但是我的问题是:当我通过序列化保存 ArrayList conditionList,然后重新加载它时,更改就消失了。所以我认为我的代码在更改 ArrayList(命名条件列表)中的字符串值时存在问题,任何人都可以看看你是否注意到问题

String conString = jListCondition.getSelectedValue().toString(); 

    for(String c: conditionList)
    {
        if(conString.compareTo(c) == 0)
        {
            String temp = entConName.getText();
            c = temp;
            //edit the Condition jList model
            int x = condListModel.indexOf(conString);
            condListModel.setElementAt(temp, x);
            jListCondition.setModel(condListModel);
            //edit the Condition comboBox model
            int i = conditionModel.getIndexOf(conString);
            conditionModel.insertElementAt(temp, i);
            conditionModel.removeElement(conString);
            entCondition.setModel(conditionModel);


            //reset buttons
            editConConfirm.setEnabled(false);
            editCon.setEnabled(false);
            deleteCon.setEnabled(false);
            entConName.setText("");
            addCon.setEnabled(true);
        }
    }
4

0 回答 0