src/java.desktop/share/classes/javax/swing/JList.java
changeset 49296 16596ba0b52c
parent 49226 091d7717bf98
child 49501 5daa8ef17089
equal deleted inserted replaced
49295:8d8f74e84ff6 49296:16596ba0b52c
  2267         ListSelectionModel sm = getSelectionModel();
  2267         ListSelectionModel sm = getSelectionModel();
  2268         ListModel<E> dm = getModel();
  2268         ListModel<E> dm = getModel();
  2269 
  2269 
  2270         int iMin = sm.getMinSelectionIndex();
  2270         int iMin = sm.getMinSelectionIndex();
  2271         int iMax = sm.getMaxSelectionIndex();
  2271         int iMax = sm.getMaxSelectionIndex();
  2272 
  2272         int size = dm.getSize();
  2273         if ((iMin < 0) || (iMax < 0)) {
  2273 
       
  2274         if ((iMin < 0) || (iMax < 0) || (iMin >= size)) {
  2274             return new Object[0];
  2275             return new Object[0];
  2275         }
  2276         }
       
  2277         iMax = iMax < size ? iMax : size - 1;
  2276 
  2278 
  2277         Object[] rvTmp = new Object[1+ (iMax - iMin)];
  2279         Object[] rvTmp = new Object[1+ (iMax - iMin)];
  2278         int n = 0;
  2280         int n = 0;
  2279         for(int i = iMin; i <= iMax; i++) {
  2281         for(int i = iMin; i <= iMax; i++) {
  2280             if (sm.isSelectedIndex(i)) {
  2282             if (sm.isSelectedIndex(i)) {
  2302         ListSelectionModel sm = getSelectionModel();
  2304         ListSelectionModel sm = getSelectionModel();
  2303         ListModel<E> dm = getModel();
  2305         ListModel<E> dm = getModel();
  2304 
  2306 
  2305         int iMin = sm.getMinSelectionIndex();
  2307         int iMin = sm.getMinSelectionIndex();
  2306         int iMax = sm.getMaxSelectionIndex();
  2308         int iMax = sm.getMaxSelectionIndex();
  2307 
  2309         int size = dm.getSize();
  2308         if ((iMin < 0) || (iMax < 0)) {
  2310 
       
  2311         if ((iMin < 0) || (iMax < 0) || (iMin >= size)) {
  2309             return Collections.emptyList();
  2312             return Collections.emptyList();
  2310         }
  2313         }
       
  2314         iMax = iMax < size ? iMax : size - 1;
  2311 
  2315 
  2312         List<E> selectedItems = new ArrayList<E>();
  2316         List<E> selectedItems = new ArrayList<E>();
  2313         for(int i = iMin; i <= iMax; i++) {
  2317         for(int i = iMin; i <= iMax; i++) {
  2314             if (sm.isSelectedIndex(i)) {
  2318             if (sm.isSelectedIndex(i)) {
  2315                 selectedItems.add(dm.getElementAt(i));
  2319                 selectedItems.add(dm.getElementAt(i));
  2351      * @see #addListSelectionListener
  2355      * @see #addListSelectionListener
  2352      */
  2356      */
  2353     @BeanProperty(bound = false)
  2357     @BeanProperty(bound = false)
  2354     public E getSelectedValue() {
  2358     public E getSelectedValue() {
  2355         int i = getMinSelectionIndex();
  2359         int i = getMinSelectionIndex();
  2356         return (i == -1) ? null : getModel().getElementAt(i);
  2360         return ((i == -1) || (i >= getModel().getSize())) ? null :
       
  2361                 getModel().getElementAt(i);
  2357     }
  2362     }
  2358 
  2363 
  2359 
  2364 
  2360     /**
  2365     /**
  2361      * Selects the specified object from the list.
  2366      * Selects the specified object from the list.