-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8321140: Add comment to note difference in Metal's JButton margins #20482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
👋 Welcome back dnguyen! A progress list of the required criteria for merging this PR into |
@DamonGuy This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 132 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some L&Fs I see margin defaults set using Button.margin
.
Where does Metal LAF finally obtain these margin values from?[top=2,left=14,bottom=2,right=14]
.
Adding your margin comment will provide clarity & quick reference since these values are not evident.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've no objections from adding a comment in the code. However, the comment looks as if hanging in the air. There are CheckBox.totalInsets
and RadioButton.totalInsets
but there's no similar property for Button
.
As for me, “Doc change” implies javadoc, but it is not the case. You're add a regular code comment which no one sees, except for developers.
The subject has be clearer in this respect. Like “Comment about difference” or “Note about difference…”, to avoid any confusion.
Updated thanks. Originally this was meant to be a visible doc change when I created the issue long ago. But after looking thru the docs for Metal and any other appropriate APIs, I couldn't find a great spot to place it other than here. I agree that the comment seems to be out of place. Do you have any suggestions for where to place it otherwise? I'm currently looking into where the Metal margin defaults are set for @honkar-jdk comment. |
I found the values to be set in |
It looks okay to me to have it has a comment in MetalLAF as it is now.
I think what @aivanov-jdk meant here is that since this is a comment, only the JBS title needs a change to reflect that it is a comment and not a javadoc change. Even if it is moved to BasicLAF, it would still be added as a comment, correct? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I still don't quite understand where the margin comes from. A comment, like the one you have currently, which points to where the values come from would be good. Adding anything to public javadoc requires a CSR. Not sure if you want to go this way. It's not worth it. If developer can customise the border, it should not be specified in javadoc. |
Metal (and the custom L&Fs) seem to use BasicLookAndFeel's default value for I agree it's more difficult to add anything to public javadocs. I can add the note to |
@@ -782,6 +807,8 @@ protected void initComponentDefaults(UIDefaults table) { | |||
"SPACE", "pressed", | |||
"released SPACE", "released" | |||
}), | |||
// margin is (2, 14, 2, 14) which is vastly larger in horizontal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see below that there is another comment saying margin is 2 all the way around, what is the difference? how are these comments placed to indicate what margins they are referring to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The below comments apply to check box and radio button; this comment applies to regular push button.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. The issue is with regular buttons as Alexey mentioned. This caused a long discussion chain described in the linked issues. Nothing to do with CheckBox or RadioButton.
@@ -782,6 +807,8 @@ protected void initComponentDefaults(UIDefaults table) { | |||
"SPACE", "pressed", | |||
"released SPACE", "released" | |||
}), | |||
// margin is (2, 14, 2, 14) which is vastly larger in horizontal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
"Button.margin", new InsetsUIResource(2, 14, 2, 14), |
It is set to the button in installDefaults
:
jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicButtonUI.java
Lines 158 to 160 in 1cd4884
if(b.getMargin() == null || (b.getMargin() instanceof UIResource)) { | |
b.setMargin(UIManager.getInsets(pp + "margin")); | |
} |
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:
jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicBorders.java
Lines 493 to 495 in 1cd4884
if (c instanceof AbstractButton) { | |
AbstractButton b = (AbstractButton)c; | |
margin = b.getMargin(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. This is what I found as well. Had a bit of trouble figuring out how to phrase the note since the comment was meant to differentiate Metal from the other default installed LAFs.
I moved it to BasicLookAndFeel.java
since that's where the values are specifically defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved it to
BasicLookAndFeel.java
since that's where the values are specifically defined.
Perhaps, we need a note in both files.
In MetalLookAndFeel.java
to refer to BasicLookAndFeel
where the margin is defined, similar to what's done for check boxes and radio button.
And in BasicLookAndFeel.java
to note that the above margins are vastly different from other L&Fs.
What about this text?
MetalLookAndFeel.java
// default margin is (2, 14, 2, 14), defined in
// BasicLookAndFeel via "Button.margin" UI property.
BasicLookAndFeel.java
// The above margin has vastly larger horizontal values when
// compared to other look and feels that don't rely on these values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, adding a note at both places looks clearer. The additional note in MetalLookAndFeel.java as above gives a quick lookup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That does sound best. Added the notes to both areas as suggested. I still don't know how to not make the note in MetalLookAndFeel.java
not feel like it's hanging, but I added the note to the same spot again. I think it's the most logical area.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, copyright years need to be updated for the files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Please, update copyright year in both files.
@DamonGuy This pull request has not yet been marked as ready for integration. |
/integrate |
Going to push as commit 6460b30.
Your commit was automatically rebased without conflicts. |
Previously in 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.
However, the non-MacOS L&F fix caused a regression and the details and original discussion can be found in 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:
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/20482/head:pull/20482
$ git checkout pull/20482
Update a local copy of the PR:
$ git checkout pull/20482
$ git pull https://git.openjdk.org/jdk.git pull/20482/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 20482
View PR using the GUI difftool:
$ git pr show -t 20482
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/20482.diff
Webrev
Link to Webrev Comment