for(int i = 0; i<total_lines; i+=3) {
cnames[cindex] = currlist.get(i);
cfactor[cindex] = currlist.get(i+1);
csymbol[cindex] = currlist.get(i+2);
//currdata.addElement(cnames[cindex]);
combocurrency.addItem(cnames[cindex]);
cindex++;
}
combocurrency = new JComboBox<String>(cnames);
当应用程序首次启动时,cnames
数组从默认文件加载字符串数据。但在运行时,当我上传新文件时,cnames
值会更新,但 combocurrency
值在应用程序中保持不变!如何通过在运行时加载新文件来覆盖组合框值?
最佳答案
利用此处的 MVC 模式并使用模型。您可以使用 DefaultComboBoxModel
或根据需要实现您自己的模型。
这里给出了一个很好的例子:Dynamically adding items to a JComboBox
关于java - 在运行时从上传的文件覆盖 JCombox 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59687183/