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

JComboBox should have a List constructor

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:

      Description



      Name: rmT116609 Date: 04/01/2004


      A DESCRIPTION OF THE REQUEST :
      Currently, JComboBox has a few constructors. One of them is an Object array constructor. Another is a Vector constructor. Vector, as an implementation class, is not a good choice for use in a constructor, and should probably not have been used. The API could be improved to achieve what the Vector constructor was probably trying to achieve, which is to have a List constructor.

      At the same time, the Vector constructor should be removed.

      The same exact problem exists on the DefaultComboBoxModel. It should be fixed there as part of the same fix.


      JUSTIFICATION :
      Adding a List constructor allows the user to use any of the following: AbstractList, ArrayList, LinkedList, Vector.

      Doing this doesn't harm existing code, since Vector implements List and code where people are passing in a Vector will still work seamlessly. They won't even know anything's different.

      However, the JComboBox API would be "silently improved" and new code could start using different List implementations...even new ones created by the developer!

      The biggest justification of all, though, remains the fact that using a Vector constructor in this way is just plain old style.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I'd like to see the Vector constructor replaced with a List constructor that works in exactly the same way.

      ACTUAL -
      Currently, there is only a Vector constructor.


      ---------- BEGIN SOURCE ----------
      List myList = new Vector();

      // Doesn't work
      JComboBox comboBox = new JComboBox( myList );

      // Does work -- sad!
      JComboBox comboBox = new JComboBox( (Vector)myList );

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Convert all of your various List implementation instances into Vectors just for the purpose of instantiating a JComboBox with them.
      (Incident Review ID: 245920)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              shickeysunw Shannon Hickey (Inactive)
              Reporter:
              rmandalasunw Ranjith Mandala (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: