RFR: 8321140: Add comment to note difference in Metal's JButton margins

Alexey Ivanov aivanov at openjdk.org
Thu Aug 15 18:34:49 UTC 2024


On Tue, 6 Aug 2024 23:12:44 GMT, Damon Nguyen <dnguyen at openjdk.org> wrote:

> Previously in [JDK-8282772](https://bugs.openjdk.org/browse/JDK-8282772), there was a fix for JButtons with HTML content alignment for non-MacOS L&Fs. This fix was to make other L&Fs in line with the Aqua fix found in [JDK-8015854](https://bugs.openjdk.org/browse/JDK-8015854).
> 
> However, the non-MacOS L&F fix caused a regression and the details and original discussion can be found in [JDK-8318590](https://bugs.openjdk.org/browse/JDK-8318590). This non-MacOS L&F fix was backed out and the current behavior for JButtons with HTML content for these L&Fs was deemed to be correct as is.
> 
> Through discussion, a note about Metal's different margin values should be added somewhere for future reference. Metal's horizontal margins are 14 where other L&Fs are zero or some small value. This discrepancy is what caused the original issue to be filed. This change is to add a comment to `MetalLookAndFeel.java` since there is no exact spot where these values are set for the margin. It's been added where other Metal components (CheckBox, RadioButton, etc.) have comments on margins as well.
> 
> Here are some L&F values for reference/comparison:
> 
> Metal's margins: [top=2,left=14,bottom=2,right=14]
> Aqua's margins: [top=0,left=2,bottom=0,right=2]
> Motif's margins: [top=2,left=4,bottom=2,right=4]
> Nimbus's margins: [top=0,left=0,bottom=0,right=0]

Changes requested by aivanov (Reviewer).

src/java.desktop/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java line 810:

> 808:                  "released SPACE", "released"
> 809:               }),
> 810:             // margin is (2, 14, 2, 14) which is vastly larger in horizontal

I still suggest adding a reference to `BasicBorder` class or `BasicLookAndFeel` where this border is defined.

The borders for check boxes and radio buttons reference `BasicBorders.RadioButtonBorder` which helps to understand where the values are coming from.

Specifically, `BasicLookAndFeel` defines `Button.margin` property:

https://github.com/openjdk/jdk/blob/1cd488436880b00c55fa91f44c115999cf686afd/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java#L729

It is set to the button in `installDefaults`:

https://github.com/openjdk/jdk/blob/1cd488436880b00c55fa91f44c115999cf686afd/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicButtonUI.java#L158-L160

`BasicBorders.getButtonBorder` returns a border which defines colours and margins; the margins come from `MarginBorder` class which just returns the margins of a button component:

https://github.com/openjdk/jdk/blob/1cd488436880b00c55fa91f44c115999cf686afd/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicBorders.java#L493-L495

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

PR Review: https://git.openjdk.org/jdk/pull/20482#pullrequestreview-2241072564
PR Review Comment: https://git.openjdk.org/jdk/pull/20482#discussion_r1718830042


More information about the client-libs-dev mailing list