Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8224262

Initializing multiple DefaultComboBoxModel with a Vector

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      I'm using Eclipse to develop on Windows 10.

      A DESCRIPTION OF THE PROBLEM :
      When I initialize multiple DefaultComboBoxModel objects with the same Vector object, and then I modify one of the DefaultComboBoxModel objects (by adding or removing items), the other ComboBoxe are also modified.

      This is unexpected because the constructor that takes a Vector says it initializes with that Vector (it looks just like the constructor that initializes with an array).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create several ComboBox<String> objects, and add them to an interface.
      Create a Vector<String> (initially empty),
      For each ComboBox, setModel to a new DefaultComboBoxModel<String>, initialized with the Vector.
      Create a String.
      Call addElement(String) on each ComboBox.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Each ComboBox will have only one element.
      ACTUAL -
      Each ComboBox has several elements.

      CUSTOMER SUBMITTED WORKAROUND :
      Initialize DefaultComboBoxModel without a Vector, and then loop through the Vector to add each element.

      FREQUENCY : always


            pardesha Pardeep Sharma
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: