RFR: 4466930: JTable.selectAll boundary handling [v2]

Abhishek Kumar abhiscxk at openjdk.org
Tue Mar 18 05:27:08 UTC 2025


On Fri, 14 Mar 2025 02:50:16 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

>> JTable.selectAll doesn't do anything if there are no rows or no columns. 
>> But it should still select all columns if there are no rows and the other way round. 
>> It is seen that isColumnSelected() will return false for all columns after calling selectAll() if there happened to be no rows.
>> 
>> Fix is made to select all columns even if there are no rows and similarly for rows if there are no columns.
>
> Prasanta Sadhukhan has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Get rowCount,columnCount upfront

If there are no rows  then most probably `selectAll` will select `column headers`.. right?

I don't understand why do we want to select all columns if there are no rows or vice-versa ?
Does it return any useful details?

Few changes can be done in the fix and test code (if fix is applicable)

src/java.desktop/share/classes/javax/swing/JTable.java line 2199:

> 2197:             SwingUtilities2.setLeadAnchorWithoutSelection(selModel, oldLead, oldAnchor);
> 2198: 
> 2199:             selModel.setValueIsAdjusting(false);

Recently added code is a subset of the code block in `if block`. Duplicate code can be refactored with helper methods.

src/java.desktop/share/classes/javax/swing/JTable.java line 2206:

> 2204:             oldAnchor = getAdjustedIndex(selModel.getAnchorSelectionIndex(), false);
> 2205: 
> 2206:             setColumnSelectionInterval(0, getColumnCount()-1);

Suggestion:

            setColumnSelectionInterval(0, getColumnCount() - 1);

test/jdk/javax/swing/JTable/TestTableSelectAll.java line 43:

> 41: 
> 42:         // TableModel with no rows, but 10 columns
> 43:         DefaultTableModel data = new DefaultTableModel(0, 10);

Proposed fix tries to handle two cases:
1. rowCount > 0 and columnCount = 0
2. columnCount > 0 and rowCount = 0

but test code covers only second case (rowCount = 0).

Test should be extended to verify both cases.

-------------

PR Review: https://git.openjdk.org/jdk/pull/24025#pullrequestreview-2692980379
PR Review Comment: https://git.openjdk.org/jdk/pull/24025#discussion_r2000216763
PR Review Comment: https://git.openjdk.org/jdk/pull/24025#discussion_r2000216991
PR Review Comment: https://git.openjdk.org/jdk/pull/24025#discussion_r2000224539


More information about the client-libs-dev mailing list