使用相同模型填充多个组合框但选择diff [英] populate multiple combobox with same model but select diff
本文介绍了使用相同模型填充多个组合框但选择diff的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了 ComboBox
的问题,我用相同的模型填充了多个 ComboBox
es,但是当我运行时我的程序并从一个ComboBox中选择一个值,它为其余的选择相同的值。
Having problems with the ComboBox
, I have populated multiple ComboBox
es with the same model, but when I run my program and select a value from one ComboBox it selects the same value for the rest.
ComboHBoy.setModel(defaultComboBoxModel);
ComboHGirl.setModel(defaultComboBoxModel);
ComboDHBoy.setModel(defaultComboBoxModel);
ComboDHGirl.setModel(defaultComboBoxModel);
推荐答案
那是因为它们都引用了相同的模型,模型的任何更改都会影响所有其他组合。
That's because they all are referenced to the same model, any change of the model will affect the all the other combos.
没有办法解决这个问题,除非每个组合框都有它自己的 DefaultComboBoxModel
。
There is no way to solve this except that every combobox have it's own DefaultComboBoxModel
.
private DefaultComboBoxModel hBoyModel= new DefaultComboBoxModel();
private DefaultComboBoxModel hGirlModel= new DefaultComboBoxModel();
//....
ComboHBoy.setModel(hBoyModel);
ComboHGirl.setModel(hGrilModel);
//....
这篇关于使用相同模型填充多个组合框但选择diff的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文