< prev index next >

## src/java.desktop/share/classes/javax/swing/DefaultComboBoxModel.java

Print this page

    rev 48358 : Work in progress for JDK-6303622
    Use generic in Swing components like JComboBox
    1. Added generic return type and parameter type for JComboBox.
    2. Modified JList related classes as well.

    @@ -38,11 +38,11 @@
      * @since 1.2
      */
     @SuppressWarnings("serial") // Superclass is not serializable across versions
     public class DefaultComboBoxModel<E> extends AbstractListModel<E> implements MutableComboBoxModel<E>, Serializable {
         Vector<E> objects;
    -    Object selectedObject;
    +    E selectedObject;

         /**
          * Constructs an empty DefaultComboBoxModel object.
          */
         public DefaultComboBoxModel() {

    @@ -85,20 +85,22 @@
         /**
          * Set the value of the selected item. The selected item may be null.
          *
          * @param anObject The combo box value or null for no selection.
          */
    -    public void setSelectedItem(Object anObject) {
    +    @Override
    +    public void setSelectedItem(E anObject) {
             if ((selectedObject != null && !selectedObject.equals( anObject )) ||
                 selectedObject == null && anObject != null) {
                 selectedObject = anObject;
                 fireContentsChanged(this, -1, -1);
             }
         }

         // implements javax.swing.ComboBoxModel
    -    public Object getSelectedItem() {
    +    @Override
    +    public E getSelectedItem() {
             return selectedObject;
         }

         // implements javax.swing.ListModel
         public int getSize() {

    @@ -118,11 +120,11 @@
          *
          * @param anObject the object to return the index of
          * @return an int representing the index position, where 0 is
          *         the first position
          */
    -    public int getIndexOf(Object anObject) {
    +    public int getIndexOf(E anObject) {
             return objects.indexOf(anObject);
         }

         // implements javax.swing.MutableComboBoxModel
         public void addElement(E anObject) {

    @@ -154,11 +156,11 @@

             fireIntervalRemoved(this, index, index);
         }

         // implements javax.swing.MutableComboBoxModel
    -    public void removeElement(Object anObject) {
    +    public void removeElement(E anObject) {
             int index = objects.indexOf(anObject);
             if ( index != -1 ) {
                 removeElementAt(index);
             }
         }

< prev index next >