Skip to content

8375573: JTable ignores setPreferredWidth during initial layout when AUTO_RESIZE_LAST_COLUMN is enabled - #29291

Closed
prsadhuk wants to merge 4 commits into
openjdk:masterfrom
prsadhuk:JDK-8375573
Closed

8375573: JTable ignores setPreferredWidth during initial layout when AUTO_RESIZE_LAST_COLUMN is enabled#29291
prsadhuk wants to merge 4 commits into
openjdk:masterfrom
prsadhuk:JDK-8375573

Conversation

@prsadhuk

@prsadhuk prsadhuk commented Jan 19, 2026

Copy link
Copy Markdown
Contributor

AUTO_RESIZE_LAST_COLUMN handling was done in JDK-8234071 but it didn't honour the preferred width if it is already been set for each column so when layouting is done, it only sees the resizingColumn
is set to AUTO_RESIZE_LAST_COLUMN and adjust only the last column and distribute width equally to all other column.

Fix is made to honour the user-set preferred column width even if auto-resize mode is set to LAST_COLUMN


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8375573: JTable ignores setPreferredWidth during initial layout when AUTO_RESIZE_LAST_COLUMN is enabled (Bug - P3)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/29291/head:pull/29291
$ git checkout pull/29291

Update a local copy of the PR:
$ git checkout pull/29291
$ git pull https://git.openjdk.org/jdk.git pull/29291/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 29291

View PR using the GUI difftool:
$ git pr show -t 29291

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/29291.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper

bridgekeeper Bot commented Jan 19, 2026

Copy link
Copy Markdown

👋 Welcome back psadhukhan! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk

openjdk Bot commented Jan 19, 2026

Copy link
Copy Markdown

@prsadhuk This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8375573: JTable ignores setPreferredWidth during initial layout when AUTO_RESIZE_LAST_COLUMN is enabled

Reviewed-by: tr

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 148 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk Bot changed the title 8375573: JTable ignores setPreferredWidth during initial layout when AUTO_RESIZE_LAST_COLUMN is enabled 8375573: JTable ignores setPreferredWidth during initial layout when AUTO_RESIZE_LAST_COLUMN is enabled Jan 19, 2026
@openjdk openjdk Bot added the client client-libs-dev@openjdk.org label Jan 19, 2026
@openjdk

openjdk Bot commented Jan 19, 2026

Copy link
Copy Markdown

@prsadhuk The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk Bot added the rfr Pull request is ready for review label Jan 19, 2026
@mlbridge

mlbridge Bot commented Jan 19, 2026

Copy link
Copy Markdown

Webrevs

// is set to last column on account of
// AUTO_RESIZE_LAST_COLUMN autoResizeMode
for (int i = 0; i < columnModel.getColumnCount(); i++) {
if (columnModel.getColumn(i).getPreferredWidth() != 75

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using hardcoded value here ? Any particular reason for checking width against value 75 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because default width is such and there is no way to ascertain default width..

* Returns the width of the <code>TableColumn</code>. The default width is
* 75.

* Returns the preferred width of the <code>TableColumn</code>.
* The default preferred width is 75.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, it's been set here -

@prsadhuk prsadhuk Jan 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TejeshR13 any other comments?

for (int i = 0; i < columnModel.getColumnCount(); i++) {
if (columnModel.getColumn(i).getPreferredWidth() != 75
&& columnModel.getColumn(i).getWidth() == 75) {
prefWidthSet = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can break the loop for first true condition instead of iterating through all the columns ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, can do..Updated..

" initial layout when AUTO_RESIZE_LAST_COLUMN is enabled");
}
} finally {
if (frame != null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally we do this inside EDT.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its already under EDT

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see this is in EDT. But now this one will throw InvocationTargetException along with RuntimeException ? I guess it's better to move out the exception handling outside EDT.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont think it matters..There are many tests that follows this..throwing exception inside EDT..
additionally it will result in volatile usage of columnCount/width which we can avoid here..

@openjdk openjdk Bot added the ready Pull request is ready to be integrated label Jan 23, 2026
@prsadhuk

Copy link
Copy Markdown
Contributor Author

/integrate

@openjdk

openjdk Bot commented Jan 30, 2026

Copy link
Copy Markdown

Going to push as commit 55375e9.
Since your change was applied there have been 252 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk Bot added the integrated Pull request has been integrated label Jan 30, 2026
@openjdk openjdk Bot closed this Jan 30, 2026
@openjdk openjdk Bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jan 30, 2026
@prsadhuk
prsadhuk deleted the JDK-8375573 branch January 30, 2026 08:31
@openjdk

openjdk Bot commented Jan 30, 2026

Copy link
Copy Markdown

@prsadhuk Pushed as commit 55375e9.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client client-libs-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

2 participants