On Tue, 10 May 2022 19:03:23 GMT, Damon Nguyen <[email protected]> wrote:

>> The insets for buttons were incorrect for L&Fs except for Aqua when the text 
>> is set to HTML. This was fixed in Aqua by adding a conditional to check for 
>> the BasicHTML property key in the button component. This same logic can be 
>> used to fix Metal & Motif L&Fs in BasicButtonUI, but Nimbus is not fixed by 
>> this. Nimbus gets its default values from a skin.laf file, and when the 
>> defaults here are set to have left & right insets to 0 for ButtonUI, the 
>> issue is fixed. I also tested for non-HTML text after the changes, and the 
>> changes do not affect normal text.
>> 
>> The HtmlButtonImageTest has been changed to cycle through all L&Fs available 
>> on a device.
>
> Damon Nguyen has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Added string buffer. Separated fail images. Changed exception to throw at 
> the end of test.

I really wonder why the (10 year old) issue 
[JDK-8015854](https://bugs.openjdk.org/browse/JDK-8015854) was accepted as bug. 
😕 
It is **not a bug in JDK**, it is a bug in users code.

He sets the preferred size of the button to 30x30 and adds an HTML image to 
that button and expects that it is painted centered.
But he ignores (or does not know) that a button has a margin (2,14,2,14 in 
Metal).
Subtracting the margin from the preferred size results in a view size of 2x26 
pixel.
This view is centered withing the component bounds and the HTML image/text is 
painted left-top aligned in that view.
This paints the HTML image/text out of center, but this is **expected 
behavior**.

![image](https://github.com/openjdk/jdk/assets/5604048/d3501d38-c6ae-4475-be2c-bc3f2973dbd4)

If the user reduces the preferred size, he also needs to **reduce the margin**.
E.g. adding following line to users code (from JDK-8015854) fixes the problem:

~~~java
testButton.setMargin(new Insets(0, 0, 0, 0));
~~~

![image](https://github.com/openjdk/jdk/assets/5604048/96e00dad-e673-4598-9147-4702955086c6)

I would recommend to **revert** this PR and also PR #7310.
Both break compatibility when using HTML text in buttons.

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

PR Comment: https://git.openjdk.org/jdk/pull/8407#issuecomment-1762926635

Reply via email to