JDK-5025176 : JComboBox should have a List constructor
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-04-01
  • Updated: 2004-04-01
  • Resolved: 2004-04-01
Related Reports
Duplicate :  
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) 
======================================================================

Comments
EVALUATION Closing as a duplicate of 4304287. ###@###.### 2004-04-01
01-04-2004