|
1 | 1 | /*
|
2 |
| - * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
@@ -2146,42 +2146,54 @@ public boolean getCellSelectionEnabled() {
|
2146 | 2146 | return getRowSelectionAllowed() && getColumnSelectionAllowed();
|
2147 | 2147 | }
|
2148 | 2148 |
|
2149 |
| - /** |
2150 |
| - * Selects all rows, columns, and cells in the table. |
2151 |
| - */ |
2152 |
| - public void selectAll() { |
2153 |
| - // If I'm currently editing, then I should stop editing |
2154 |
| - if (isEditing()) { |
2155 |
| - removeEditor(); |
2156 |
| - } |
2157 |
| - if (getRowCount() > 0 && getColumnCount() > 0) { |
2158 |
| - int oldLead; |
2159 |
| - int oldAnchor; |
2160 |
| - ListSelectionModel selModel; |
| 2149 | + private void selectRows(int rowCount) { |
| 2150 | + ListSelectionModel selModel = selectionModel; |
| 2151 | + selModel.setValueIsAdjusting(true); |
| 2152 | + int oldLead = getAdjustedIndex(selModel.getLeadSelectionIndex(), true); |
| 2153 | + int oldAnchor = getAdjustedIndex(selModel.getAnchorSelectionIndex(), true); |
2161 | 2154 |
|
2162 |
| - selModel = selectionModel; |
2163 |
| - selModel.setValueIsAdjusting(true); |
2164 |
| - oldLead = getAdjustedIndex(selModel.getLeadSelectionIndex(), true); |
2165 |
| - oldAnchor = getAdjustedIndex(selModel.getAnchorSelectionIndex(), true); |
| 2155 | + setRowSelectionInterval(0, rowCount - 1); |
2166 | 2156 |
|
2167 |
| - setRowSelectionInterval(0, getRowCount()-1); |
| 2157 | + // this is done to restore the anchor and lead |
| 2158 | + SwingUtilities2.setLeadAnchorWithoutSelection(selModel, oldLead, oldAnchor); |
| 2159 | + |
| 2160 | + selModel.setValueIsAdjusting(false); |
| 2161 | + } |
2168 | 2162 |
|
2169 |
| - // this is done to restore the anchor and lead |
2170 |
| - SwingUtilities2.setLeadAnchorWithoutSelection(selModel, oldLead, oldAnchor); |
| 2163 | + private void selectColumns(int columnCount) { |
| 2164 | + ListSelectionModel selModel = columnModel.getSelectionModel(); |
| 2165 | + selModel.setValueIsAdjusting(true); |
| 2166 | + int oldLead = getAdjustedIndex(selModel.getLeadSelectionIndex(), false); |
| 2167 | + int oldAnchor = getAdjustedIndex(selModel.getAnchorSelectionIndex(), false); |
2171 | 2168 |
|
2172 |
| - selModel.setValueIsAdjusting(false); |
| 2169 | + setColumnSelectionInterval(0, columnCount - 1); |
2173 | 2170 |
|
2174 |
| - selModel = columnModel.getSelectionModel(); |
2175 |
| - selModel.setValueIsAdjusting(true); |
2176 |
| - oldLead = getAdjustedIndex(selModel.getLeadSelectionIndex(), false); |
2177 |
| - oldAnchor = getAdjustedIndex(selModel.getAnchorSelectionIndex(), false); |
| 2171 | + // this is done to restore the anchor and lead |
| 2172 | + SwingUtilities2.setLeadAnchorWithoutSelection(selModel, oldLead, oldAnchor); |
2178 | 2173 |
|
2179 |
| - setColumnSelectionInterval(0, getColumnCount()-1); |
| 2174 | + selModel.setValueIsAdjusting(false); |
| 2175 | + } |
2180 | 2176 |
|
2181 |
| - // this is done to restore the anchor and lead |
2182 |
| - SwingUtilities2.setLeadAnchorWithoutSelection(selModel, oldLead, oldAnchor); |
| 2177 | + /** |
| 2178 | + * Selects all rows, columns, and cells in the table. |
| 2179 | + */ |
| 2180 | + public void selectAll() { |
| 2181 | + int rowCount = getRowCount(); |
| 2182 | + int columnCount = getColumnCount(); |
2183 | 2183 |
|
2184 |
| - selModel.setValueIsAdjusting(false); |
| 2184 | + // If I'm currently editing, then I should stop editing |
| 2185 | + if (isEditing()) { |
| 2186 | + removeEditor(); |
| 2187 | + } |
| 2188 | + if (rowCount > 0 && columnCount > 0) { |
| 2189 | + selectRows(rowCount); |
| 2190 | + selectColumns(columnCount); |
| 2191 | + } else if (rowCount > 0 && columnCount == 0 |
| 2192 | + && getRowSelectionAllowed()) { |
| 2193 | + selectRows(rowCount); |
| 2194 | + } else if (columnCount > 0 && rowCount == 0 |
| 2195 | + && getColumnSelectionAllowed()) { |
| 2196 | + selectColumns(columnCount); |
2185 | 2197 | }
|
2186 | 2198 | }
|
2187 | 2199 |
|
|
0 commit comments