< prev index next >

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

Print this page

    rev 48858 : 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.
    3. Reverted the changes made to "getSelectedValues" as suggested by Joe.
    4. Modified files that were failing on Linux and Mac as well.

    @@ -2262,30 +2262,11 @@
          * @deprecated As of JDK 1.7, replaced by {@link #getSelectedValuesList()}
          */
         @Deprecated
         @BeanProperty(bound = false)
         public Object[] getSelectedValues() {
    -        ListSelectionModel sm = getSelectionModel();
    -        ListModel<E> dm = getModel();
    -
    -        int iMin = sm.getMinSelectionIndex();
    -        int iMax = sm.getMaxSelectionIndex();
    -
    -        if ((iMin < 0) || (iMax < 0)) {
    -            return new Object[0];
    -        }
    -
    -        Object[] rvTmp = new Object[1+ (iMax - iMin)];
    -        int n = 0;
    -        for(int i = iMin; i <= iMax; i++) {
    -            if (sm.isSelectedIndex(i)) {
    -                rvTmp[n++] = dm.getElementAt(i);
    -            }
    -        }
    -        Object[] rv = new Object[n];
    -        System.arraycopy(rvTmp, 0, rv, 0, n);
    -        return rv;
    +        return getSelectedValuesList().toArray();
         }

         /**
          * Returns a list of all the selected items, in increasing order based
          * on their indices in the list.

    @@ -2358,15 +2339,16 @@

         /**
          * Selects the specified object from the list.
          *
    +     * @param <E> the type of the elements of this JList.
          * @param anObject      the object to select
          * @param shouldScroll  {@code true} if the list should scroll to display
          *                      the selected object, if one exists; otherwise {@code false}
          */
    -    public void setSelectedValue(Object anObject,boolean shouldScroll) {
    +    public void setSelectedValue(E anObject,boolean shouldScroll) {
             if(anObject == null)
                 setSelectedIndex(-1);
             else if(!anObject.equals(getSelectedValue())) {
                 int i,c;
                 ListModel<E> dm = getModel();

< prev index next >