RFR: 6292135: DefaultTableModel.setColumnIdentifiers() Clears JTable Row Heights [v2]
Tejesh R
tr at openjdk.org
Fri Dec 12 07:34:00 UTC 2025
On Fri, 12 Dec 2025 05:56:38 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:
>> Calling `DefaultTableModel.setColumnIdentifiers()` resizes the row height of the table to default row height (16) even if the row height is changed to something other than the default using `JTable.setRowHeight(row, height).`
>> The spec of `DefaultTableModel.setColumnIdentifiers()` https://docs.oracle.com/en/java/javase/24/docs/api/java.desktop/javax/swing/table/DefaultTableModel.html#setColumnIdentifiers(java.lang.Object[]) says that it
>> `replaces the column identifiers in the model`, that is, the header field of the column is changed to the passed identifier and nowhere it is mentioned that row height would be changed.
>>
>> The issue happens because calling `DefaultTableModel.setColumnIdentifiers()` results in the firing of a `TableModelEvent` with HEADER_ROW event and JTable resets the `rowModel` for it irrespective of what the event is.
>> Fix is to not reset the `rowModel` to keep the set rowHeight intact for HEADER_ROW event
>>
>> No other issue observed with CI with this fix..
>
> Prasanta Sadhukhan has updated the pull request incrementally with one additional commit since the last revision:
>
> Test headless
test/jdk/javax/swing/JTable/TestRowHeightWithColIdentifier.java line 41:
> 39: private static JTable table;
> 40: private static volatile int oldRowHeight;
> 41: private static volatile int curRowHeight;
All these declarations can be moved inside now.
test/jdk/javax/swing/JTable/TestRowHeightWithColIdentifier.java line 60:
> 58: model.setColumnIdentifiers(new Object[] {"Check", "it out!"});
> 59: for (int row = 0; row < table.getRowCount(); row++) {
> 60: System.out.println("AFter table rowHeight " + table.getRowHeight(row));
Suggestion:
System.out.println("After table rowHeight " + table.getRowHeight(row));
test/jdk/javax/swing/JTable/TestRowHeightWithColIdentifier.java line 64:
> 62: curRowHeight = table.getRowHeight(0);
> 63: if (curRowHeight != oldRowHeight) {
> 64: throw new RuntimeException("DefaultTableModel.setColumnIdentifiers() Clears JTable Row Heights");
Suggestion:
throw new RuntimeException("DefaultTableModel.setColumnIdentifiers() Clears JTable Row Height");
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28529#discussion_r2613219134
PR Review Comment: https://git.openjdk.org/jdk/pull/28529#discussion_r2613220592
PR Review Comment: https://git.openjdk.org/jdk/pull/28529#discussion_r2613221422
More information about the client-libs-dev
mailing list