RFR: 8302173: Button border overlaps with button icon on macOS system LaF

Damon Nguyen dnguyen at openjdk.org
Tue Feb 14 19:34:46 UTC 2023


On Tue, 14 Feb 2023 02:19:15 GMT, Harshitha Onkar <honkar at openjdk.org> wrote:

>> Previous fix to HTML in AquaButtonUI fixed spacing issue for HTML images in a JButton in Aqua L&F. The new issue comes from having text inside the HTML as the button's text. If an icon is used, this icon exceeds the bounds of the button and overlaps the border.
>> 
>> Added additional logic to check if HTML contains an img. If so, apply the previous fix. Otherwise, the original implementation for Aqua's JButton HTML layout works correctly, so use this behavior.
>> 
>> Added a test based on the provided test in the bug report. Automated the test using a BufferedImage and changed the icon color to RED. Tested with multiple runs on Aqua L&F, and the test passes with the update where it fails without the update.
>
> src/java.desktop/macosx/classes/com/apple/laf/AquaButtonUI.java line 343:
> 
>> 341:         final String text;
>> 342:         final View v = (View)c.getClientProperty(BasicHTML.propertyKey);
>> 343:         if (v != null && ((AbstractButton) c).getText().contains("<img ")) {
> 
> You might want to test a combination of HTML image + icon added to JButton, to make sure the fix works correctly under different combinations.
> 
> Suggestion: Does having `((AbstractButton) c).getIcon() == null` make it more robust than checking for html tag patterns ?

The icon isn't the HTML image like in the similar test `HtmlButtonImageTest`. This time the HTML is the text and the icon is simply a separate image. This is the cause of the issue. The importance will be if the HTML contents is actually an image or just HTML text.

> test/jdk/javax/swing/JButton/HtmlButtonWithTextAndIcon.java line 57:
> 
>> 55:     private static final int BUTTON_WIDTH = 59;
>> 56:     private static final int BUTTON_HEIGHT = 28;
>> 57:     private static final int ICON_WIDTH = 16;
> 
> To make testing easier with different icon & button sizes, it is better to have button width and height as a factor of icon size (1.5 times or greater) as mentioned here [JDK-8015854](https://bugs.openjdk.org/browse/JDK-8015854).

I had the same thought, but decided to use these values for width and height due to wanting to match the provided test in the issue. This was to best mimic the overlapping displayed in the screenshots, and using these fixed values seems like the best way for me to replicate the overlapping. These are the width & height values of the button in the original test provided so I used the same icon size, text, and button dimensions.

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

PR: https://git.openjdk.org/jdk/pull/12520



More information about the client-libs-dev mailing list