Hi David,
I stumbled upon this message in my inbox and realised I hadn't replied
your latest questions.
On 2025-08-30 15:15, David Alayachew wrote:
Thanks Alexey,
I use 125%, so looks like I got the unlucky hand here. And thanks
about the multiple of 4 detail.
I understand that this is a difficult problem to fix, but this is
still something that will eventually be fixed, right? Or is this
something that will just not be addressed?
I hope this problem will get fixed eventually. At the same time, I don't
see an easy way to do so.
I believe the button in your test case falls at an “edge” of pixel grid.
When the parent component is painted, the button is clipped from erasing
the background, and the clip area ends up being 1 pixel larger than the
area which the button paints. This is how you can see the garbage left
in the back buffer.
We may need to look at the approaches other UI frameworks employ. As far
as I know, Java FX handles scaling better than Swing. As an example, a
layout manager could ensure that the coordinates and the width and
height of each component are multiples of 4, the gaps between components
should also be multiples of 4. But it still could break UI layouts… just
in a different way.
As always, any suggestions on how to tackle the problem, including
patches, are welcome.
--
Regards,
Alexey
Thank you for your time and help.
David Alayachew
On Fri, Aug 29, 2025, 5:24 AM Alexey Ivanov <[email protected]>
wrote:
Hi David,
It is a known issue because of fractional scale. Unfortunately,
it's not
so easy to fix. The artifact that you see is the result of
rounding: the
button should've painted more pixels, but it didn't, therefore you
see
garbage left in the back buffer.
What is the default / recommended scale on your system? I assume it's
150%, which is the most common scale for laptops and monitors.
With 125% and 175%, you usually get more artifacts than with 150%.
With
integral scales, 200%, the UI usually looks good without artifacts.
To workaround, you can increase the height of the button. In
general, if
you use coordinates and widths and heights that are multiples of
4, you
shouldn't see such artifacts because the standard scales will
produce an
integer.
Your test case on Stack Overflow can be minimised to display only the
button. If its coordinates and its width and height aren't
multiples of
4, there are high chances of seeing artifacts, however, this requires
the back buffer to contain garbage that's not filled with the
background
colour of the frame.
If you have a JBS account, you can click "Start watching this
issue" to
receive notifications when it's changed.
--
Regards,
Alexey
On 2025-08-29 04:40, David Alayachew wrote:
> Ty vm Prasanta. Please keep me in the loop. I will also check
back in
> to the JBS page on occasion to see progress on this.
>
> On Thu, Aug 28, 2025 at 10:23 PM Prasanta Sadhukhan
> <[email protected]> wrote:
>
> Hi David,
>
> It seems to be a bug and its there from JDK9 when HiDPI feature
> was introduced in 2015..We will look into it but cannot
commit on
> a timeframe for now..
>
> Regards
> Prasanta
> On 28-08-2025 04:11, David Alayachew wrote:
>> Hello @[email protected]
>> <mailto:[email protected]>,
>>
>> Here is my StackOverflow post --
>>
https://stackoverflow.com/questions/79748482/how-do-i-get-rid-of-these-artifacts-on-my-jbutton-and-or-what-am-i-doing-wrong
<https://urldefense.com/v3/__https://stackoverflow.com/questions/79748482/how-do-i-get-rid-of-these-artifacts-on-my-jbutton-and-or-what-am-i-doing-wrong__;!!ACWV5N9M2RV99hQ!PCN9WQxrtDa26-bo7WfYqg5k4dYWSuT5FhHWJFLQSBdWqJOY0hccMnH-4RZaQo6xnJSHkZgbj1lRFTnW3SczyElChE0h$>
>>
>> I have a simple Swing GUI that takes in an image, puts it in a
>> JPanel via JLabel, then adds a button to that same JPanel. When
>> doing so, I get artifacts at the bottom of my JButton. You can
>> see the StackOverflow post to see the code example and the
artifacts.
>>
>> I was directed to the following bug entry --
>> https://bugs.openjdk.org/browse/JDK-8253530
>>
>> Long story short, the issue is with the default scaling set for
>> HI DPI monitors on Windows 11 (maybe other versions too?). If I
>> set the scaling down to 100%, this issue goes away, and things
>> work as expected.
>>
>> Anyways, my question is, is the linked bug something that is
>> being considered? Based on the comments on it, looks like it is
>> being treated as not an issue, but it wasn't flagged as such.
>>
>> Thanks for your time and consideration.
>> David Alayachew
>