0

I am getting what, to me, seems like odd behavior. I've created createComboBoxModel. I then create 2 new JComboBoxes and add the model to each as ComboBoxDefaultModel. Although the combo boxes are different instances, using the model seems to somehow tie the 2 together. When I make a selection in one combobox it forces the same selection in the other combobox as well. Is this the way it is supposed to behave and if so why? If not then do I have some kind of coding error that causes this behavior? TIA.

Wt Riker
  • 514
  • 12
  • 24
  • 1
    It's the way models work. 2 UI components that are based on the same model will reflect the models state. – René Link Jun 19 '17 at 15:51
  • Thanks for the reply. Since they are different instances of comboboxes, it just seems odd that it would be designed that way. Off hand I cannot think of a practical use for that "feature." – Wt Riker Jun 19 '17 at 15:55
  • For [example](https://stackoverflow.com/a/3191882/230513). – trashgod Jun 19 '17 at 16:00
  • If it makes sense or not depends on your use case. E.g. if you have an application that create 2 frames and you want to allow the user to select an element of a list in both frames. Then it makes sense to have one model that the application can access and modify and 2 ui representations in each frame. The advantage would be that you don't have to worry about synchronization of the 2 ui components. – René Link Jun 19 '17 at 16:09
  • Thanks. I guess since I've never seen that situation it is why that never occurred to me. – Wt Riker Jun 19 '17 at 17:13

0 Answers0