Skip to content

Conversation

@rajamah
Copy link
Member

@rajamah rajamah commented Jun 27, 2025

Modified the code to account for border thickness correctly and updated the related tests to make sure we are testing the new change.

Testing done.


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-8349188: LineBorder does not scale correctly (Bug - P3)

Reviewers

Contributors

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26025

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 27, 2025

👋 Welcome back rmahajan! 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
Copy link

openjdk bot commented Jun 27, 2025

@rajamah 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:

8349188: LineBorder does not scale correctly

Co-authored-by: Alexey Ivanov <[email protected]>
Reviewed-by: aivanov, serb

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 207 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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@aivanov-jdk, @mrserb) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 27, 2025
@openjdk
Copy link

openjdk bot commented Jun 27, 2025

@rajamah 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.

@rajamah rajamah changed the title 8349188: Expand bug8033699.java to iterate over all LaFs 8349188: LineBorder does not scale correctly Jun 27, 2025
@rajamah
Copy link
Member Author

rajamah commented Jun 27, 2025

/contributor add @aivanov-jdk

@openjdk
Copy link

openjdk bot commented Jun 27, 2025

@rajamah
Contributor Alexey Ivanov <[email protected]> successfully added.

@mlbridge
Copy link

mlbridge bot commented Jun 27, 2025

Webrevs

Copy link
Member

@aivanov-jdk aivanov-jdk left a comment

Choose a reason for hiding this comment

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

Looks good except for a few nits.

Shape inner;

int offs = this.thickness * (int) scaleFactor;
int offs = clipRound(this.thickness * scaleFactor);
Copy link
Member

Choose a reason for hiding this comment

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

Please double-check whether you need to use Region.clipScale() instead.

I actually do not remember when to use one over the other. Maybe if you find a review request for the patch where these methods were added, you can confirm which one should be used. I checked the current source, and it seems that we randomly use one or the other, which seems incorrect.

Copy link
Member

Choose a reason for hiding this comment

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

it might be possible we should use one for the left/top part and another for the right/bottom so we will not create a gaps.

Copy link
Member

@aivanov-jdk aivanov-jdk Jun 28, 2025

Choose a reason for hiding this comment

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

Please double-check whether you need to use Region.clipScale() instead.

@mrserb We use Region.clipRound for converting coordinates in SwingUtilities3.paintBorder:

double xx = at.getScaleX() * x + at.getTranslateX();
double yy = at.getScaleY() * y + at.getTranslateY();
xtranslation = clipRound(xx);
ytranslation = clipRound(yy);
width = clipRound(at.getScaleX() * w + xx) - xtranslation;
height = clipRound(at.getScaleY() * h + yy) - ytranslation;

These formulas were introduced in #10681 (JDK-8282958); and after refactoring #11571 (JDK-8294680), the new formulas resolved JDK-8294921 after #7449 (JDK-8279614) where there was a gap between the component edge and its border. These formulas specifically addressed the situation with gaps and were developed while we worked on making LineBorder and EtchedBorder render better at fractional scales.

So, using clipRound seems good enough. Initially, I suggested using (int) (this.thickness * scaleFactor), but clipRound gives better results.

I actually do not remember when to use one over the other. Maybe if you find a review request for the patch where these methods were added, you can confirm which one should be used.

I couldn't find anything explaining where clipScale is better than clipRound. The discussion for JDK-8000629 started in March 2013 and continued in April 2013.

I checked the current source, and it seems that we randomly use one or the other, which seems incorrect.

The javadoc for neither clipScale nor clipRound provides an example where each method is best suitable. So, it's not that surprising either is used randomly…

It seems to me, that both clipScale and clipRound yield the same result. The former uses Math.round, whereas the latter uses Math.ceil after subtracting 0.5.

it might be possible we should use one for the left/top part and another for the right/bottom so we will not create a gaps.

Perhaps… However, I'm pretty sure gaps are still possible whatever method we choose because fractional pixels don't fit nicely into the pixel grid.

Copy link
Member

Choose a reason for hiding this comment

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

I am pretty sure these methods produce different results for negative coordinates.

Copy link
Member

@mrserb mrserb Jun 29, 2025

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@mrserb Putting the discussions aside, does the suggested fix look good to you?

As I said, border painting uses clipRound consistently: both in coordinate calculation and in thickness calculation. This approach resolves the problem reported.

Looking at descriptions of clipScale and clipRound, it seems the former suits better… Yet it makes the rendering less consistent with other borders: using clipScale switches to 2-pixel and 3-pixel border at 1.50 and 2.50 correspondingly (from 1 and 2 with clipRound). In other cases, the border thickness also increases, which may be undesirable.

Overall, there are 6 failures of the ScaledLineBorderTest.java test when the code in JDK uses clipScale instead of clipRound.

Copy link
Member

Choose a reason for hiding this comment

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

I looked at another test case Rajat and I discussed, and using clipScale doesn't help there either. I prefer rendering with clipRound.

Copy link
Member

Choose a reason for hiding this comment

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

My point is to investigate the difference between clipScale and clipRound to ensure the correct one is used. There was a complex discussion before about similar issue, which is why we currently have two separate versions of this rounding logic. Simply replacing one with the other might not work and some other tweaks should be done.

Copy link
Member

@aivanov-jdk aivanov-jdk Jun 30, 2025

Choose a reason for hiding this comment

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

My point is clipRound works good in this use case, it resolves the problem, I see no reason not to accept the fix.


I agree with your general concern that we should understand better the purpose of each method. Yet no one seems to remember the outcome of that complex discussion, therefore switching to clipScale could be postponed; if it's deemed necessary, we can easily change the method, both in the implementation and in the test.

I submitted JDK-8361095 to ensure this current discussion isn't forgotten and we figure out the purpose and guidelines for clipScale and clipRound.

Copy link
Member

Choose a reason for hiding this comment

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

Ok sounds good.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 28, 2025
@rajamah
Copy link
Member Author

rajamah commented Jul 2, 2025

/integrate

@aivanov-jdk
Copy link
Member

Nudge the Skara bots with a comment…

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jul 3, 2025
@openjdk
Copy link

openjdk bot commented Jul 3, 2025

@rajamah
Your change (at version f6af4cb) is now ready to be sponsored by a Committer.

@aivanov-jdk
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Jul 3, 2025

Going to push as commit 24117c6.
Since your change was applied there have been 207 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 Jul 3, 2025
@openjdk openjdk bot closed this Jul 3, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jul 3, 2025
@openjdk openjdk bot removed the sponsor Pull request is ready to be sponsored label Jul 3, 2025
@openjdk
Copy link

openjdk bot commented Jul 3, 2025

@aivanov-jdk @rajamah Pushed as commit 24117c6.

💡 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 [email protected] integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants