< prev index next >

src/share/classes/javax/swing/JTable.java

Print this page
rev 14331 : 8074286: Add getSelectedIndices() to ListSelectionModel
Reviewed-by: serb, psadhukhan


2244         return selectionModel.getMinSelectionIndex();
2245     }
2246 
2247     /**
2248      * Returns the index of the first selected column,
2249      * -1 if no column is selected.
2250      * @return the index of the first selected column
2251      */
2252     public int getSelectedColumn() {
2253         return columnModel.getSelectionModel().getMinSelectionIndex();
2254     }
2255 
2256     /**
2257      * Returns the indices of all selected rows.
2258      *
2259      * @return an array of integers containing the indices of all selected rows,
2260      *         or an empty array if no row is selected
2261      * @see #getSelectedRow
2262      */
2263     public int[] getSelectedRows() {
2264         int iMin = selectionModel.getMinSelectionIndex();
2265         int iMax = selectionModel.getMaxSelectionIndex();
2266 
2267         if ((iMin == -1) || (iMax == -1)) {
2268             return new int[0];
2269         }
2270 
2271         int[] rvTmp = new int[1+ (iMax - iMin)];
2272         int n = 0;
2273         for(int i = iMin; i <= iMax; i++) {
2274             if (selectionModel.isSelectedIndex(i)) {
2275                 rvTmp[n++] = i;
2276             }
2277         }
2278         int[] rv = new int[n];
2279         System.arraycopy(rvTmp, 0, rv, 0, n);
2280         return rv;
2281     }
2282 
2283     /**
2284      * Returns the indices of all selected columns.
2285      *
2286      * @return an array of integers containing the indices of all selected columns,
2287      *         or an empty array if no column is selected
2288      * @see #getSelectedColumn
2289      */
2290     public int[] getSelectedColumns() {
2291         return columnModel.getSelectedColumns();
2292     }
2293 
2294     /**
2295      * Returns the number of selected rows.
2296      *
2297      * @return the number of selected rows, 0 if no rows are selected
2298      */
2299     public int getSelectedRowCount() {
2300         int iMin = selectionModel.getMinSelectionIndex();
2301         int iMax = selectionModel.getMaxSelectionIndex();
2302         int count = 0;
2303 
2304         for(int i = iMin; i <= iMax; i++) {
2305             if (selectionModel.isSelectedIndex(i)) {
2306                 count++;
2307             }
2308         }
2309         return count;
2310     }
2311 
2312     /**
2313      * Returns the number of selected columns.
2314      *
2315      * @return the number of selected columns, 0 if no columns are selected
2316      */
2317     public int getSelectedColumnCount() {
2318         return columnModel.getSelectedColumnCount();
2319     }
2320 
2321     /**
2322      * Returns true if the specified index is in the valid range of rows,
2323      * and the row at that index is selected.
2324      *
2325      * @return true if <code>row</code> is a valid index and the row at
2326      *              that index is selected (where 0 is the first row)
2327      */
2328     public boolean isRowSelected(int row) {
2329         return selectionModel.isSelectedIndex(row);




2244         return selectionModel.getMinSelectionIndex();
2245     }
2246 
2247     /**
2248      * Returns the index of the first selected column,
2249      * -1 if no column is selected.
2250      * @return the index of the first selected column
2251      */
2252     public int getSelectedColumn() {
2253         return columnModel.getSelectionModel().getMinSelectionIndex();
2254     }
2255 
2256     /**
2257      * Returns the indices of all selected rows.
2258      *
2259      * @return an array of integers containing the indices of all selected rows,
2260      *         or an empty array if no row is selected
2261      * @see #getSelectedRow
2262      */
2263     public int[] getSelectedRows() {
2264         return selectionModel.getSelectedIndices();
















2265     }
2266 
2267     /**
2268      * Returns the indices of all selected columns.
2269      *
2270      * @return an array of integers containing the indices of all selected columns,
2271      *         or an empty array if no column is selected
2272      * @see #getSelectedColumn
2273      */
2274     public int[] getSelectedColumns() {
2275         return columnModel.getSelectedColumns();
2276     }
2277 
2278     /**
2279      * Returns the number of selected rows.
2280      *
2281      * @return the number of selected rows, 0 if no rows are selected
2282      */
2283     public int getSelectedRowCount() {
2284         return selectionModel.getSelectedItemsCount();









2285     }
2286 
2287     /**
2288      * Returns the number of selected columns.
2289      *
2290      * @return the number of selected columns, 0 if no columns are selected
2291      */
2292     public int getSelectedColumnCount() {
2293         return columnModel.getSelectedColumnCount();
2294     }
2295 
2296     /**
2297      * Returns true if the specified index is in the valid range of rows,
2298      * and the row at that index is selected.
2299      *
2300      * @return true if <code>row</code> is a valid index and the row at
2301      *              that index is selected (where 0 is the first row)
2302      */
2303     public boolean isRowSelected(int row) {
2304         return selectionModel.isSelectedIndex(row);


< prev index next >