< prev index next >

## src/java.desktop/share/classes/javax/swing/JList.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.

    @@ -2252,38 +2252,43 @@

         /**
          * Returns an array of all the selected values, in increasing order based
          * on their indices in the list.
          *
    +     * @param <E> the type of the elements of this JList.
          * @return the selected values, or an empty array if nothing is selected
          * @see #isSelectedIndex
          * @see #getModel
          * @see #addListSelectionListener
          *
          * @deprecated As of JDK 1.7, replaced by {@link #getSelectedValuesList()}
          */
         @Deprecated
         @BeanProperty(bound = false)
    -    public Object[] getSelectedValues() {
    +    public E[] 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];
    +            @SuppressWarnings("unchecked")
    +            E[] res = (E[])new Object[0];
    +            return res;
             }

    -        Object[] rvTmp = new Object[1+ (iMax - iMin)];
    +        @SuppressWarnings("unchecked")
    +        E[] rvTmp = (E[]) 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];
    +        @SuppressWarnings("unchecked")
    +        E[] rv = (E[]) new Object[n];
             System.arraycopy(rvTmp, 0, rv, 0, n);
             return rv;
         }

         /**

    @@ -2358,15 +2363,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 >