java - Synchronized JList and JComboBox? -


possible duplicate:
synchronized jlist , jcombobox?

hello,

in java swing, what's best way jlist , jcombobox synchronized in terms of data, i.e., have same list of items @ given point of time? basically, if add items (or remove items from) one, other should reflect change automatically. i've tried doing following, doesn't seem work:

jlist list = new jlist(); jcombobox combobox = new jcombobox(); defaultlistmodel listmodel = new defaultlistmodel(); // add items listmodel... list.setmodel(listmodel); combobox.setmodel(new defaultcomboboxmodel(listmodel.toarray())); 

you're creating 2 models in code. when construct new defaultcomboboxmodel passing in listmodel contents constructing second model starts same contents first. won't update same. want 2 components share model. in other words...

jlist list = new jlist(); jcombobox combobox = new jcombobox(); defaultcomboboxmodel listmodel = new defaultcomboboxmodel(); // add items listmodel... list.setmodel(listmodel); combobox.setmodel(listmodel); 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -