RFR: JDK-8282772: JButton text set as HTML content has unwanted padding [v4]

Damon Nguyen dnguyen at openjdk.org
Thu Oct 19 16:03:52 UTC 2023


On Sat, 14 Oct 2023 14:13:00 GMT, Karl T <duke at openjdk.org> wrote:

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

Hi @DevCharly, I'll look into this. I see your point on how this sort of goes against expected behavior, knowing the margins are (2, 14, 2, 14). I can distinguish between HTML images and HTML text to resolve this issue somewhat for the unexpected padding, but I think reverting the PRs is also a valid solution.

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

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


More information about the client-libs-dev mailing list