On Mon, 10 Aug 2026 17:58:37 GMT, Andy Goryachev <[email protected]> wrote:

>> Prasanta Sadhukhan has updated the pull request incrementally with one 
>> additional commit since the last revision:
>> 
>>   Prevent prefWidth from being reapplied
>
> src/java.desktop/share/classes/javax/swing/JTable.java line 3289:
> 
>> 3287:         for (int i = 0; i < columnModel.getColumnCount(); i++) {
>> 3288:             TableColumn column = columnModel.getColumn(i);
>> 3289:             if (column.getPreferredWidth() != 75 && column.getWidth() 
>> == 75) {
> 
> Another suggestion is to maybe create a package protected
> 
> `static final int DEFAULT_WIDTH = 75;`
> 
> in the `TableColumn` class for use in constructors, and reference it from 
> here?
> this way it clearly establishes the relationships between related paths.
> 
> or, if you do not want to touch the `TableColumn` class, at least add a 
> comment here to explain where the constant 75 came from.

after the latest change introducing a boolean flag, this method is not needed 
and thus removed

> src/java.desktop/share/classes/javax/swing/JTable.java line 3859:
> 
>> 3857:             throw new IllegalArgumentException("Cannot set a null 
>> ColumnModel");
>> 3858:         }
>> 3859:         columnWidthsInitialized = false;
> 
> can you add a test for this case?

test is already present in test/jdk/javax/swing/JTable/TestJTableColWidth.java

> src/java.desktop/share/classes/javax/swing/JTable.java line 4673:
> 
>> 4671:      */
>> 4672:     public void columnAdded(TableColumnModelEvent e) {
>> 4673:         columnWidthsInitialized = false;
> 
> are you sure?
> 
> shouldn't it resize the _existing_ columns using their _current_ widths, but 
> use the _preferred_ width of the newly added column?

Right, modified so that if columnWidthsInitialized == true, initialize only the 
added column’s current width from its preferred width, then let normal layout 
handle the table-width delta

> src/java.desktop/share/classes/javax/swing/JTable.java line 4690:
> 
>> 4688:      */
>> 4689:     public void columnRemoved(TableColumnModelEvent e) {
>> 4690:         columnWidthsInitialized = false;
> 
> similarly here, are you sure?
> 
> if a column gets removed, it should probably not use the preferred widths, 
> but use the existing widths (since the user might have adjusted the table to 
> their liking, and we should always try to remember the user's choice).

Yes, you are right..If the table has already been shown and the user has 
adjusted widths, then removing a column should preserve the remaining columns’ 
current widths as much as possible so removed..

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

PR Review Comment: https://git.openjdk.org/jdk/pull/31704#discussion_r3756744190
PR Review Comment: https://git.openjdk.org/jdk/pull/31704#discussion_r3756740560
PR Review Comment: https://git.openjdk.org/jdk/pull/31704#discussion_r3756737065
PR Review Comment: https://git.openjdk.org/jdk/pull/31704#discussion_r3756733438

Reply via email to