-
Notifications
You must be signed in to change notification settings - Fork 5.9k
8054572: [macosx] JComboBox paints the border incorrectly #9473
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
8054572: [macosx] JComboBox paints the border incorrectly #9473
Conversation
👋 Welcome back dnguyen! A progress list of the required criteria for merging this PR into |
Webrevs
|
PassFailJFrame.addTestFrame(frame); | ||
PassFailJFrame.positionTestFrame(frame, | ||
PassFailJFrame.Position.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.
These methods need to be changed to addTestWindow
and positionTestWindow
based on the recently integrated changes to PassFailJFrame.
public static synchronized void addTestWindow(Window testWindow) { |
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 remember this conversation. I synced my local branch and updated the methods. Tested and the test still works.
// } catch (Exception e) { | ||
// | ||
// } | ||
|
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.
Might have missed removing commented lines
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.
Thanks for catching that. I also added a few newlines for long lines of code. I think I forgot to save my latest changes.
Can you please show before and after fix image of the editable combobox? Also, I think if you try with different font size e.g. you will again see the editable combobox button height is not matching textfield height whereas non editable one it is aligned.. |
I have additional images on JBS, but I'll gladly post them here as well. I'm looking into the text size and the borders. The sizing of the button seems to also be affected by a component size value, so I'm adjusting that instead. |
I am not getting the same uniform blue border around textfield and button as can be seen in my screenshot with your test, which is seen in your image (with fix), so I asked to remove that incomplete blue border.. I am testing on BigSur 11.6..which os version is yours? |
Since the arrowButton is rendered by JRS, it needs to be instucted not to draw the border in that case..The above methods will not work as JRSUIPainter does not know about that, so one can call |
The solution I worked towards was to match the behavior of the non-editable combo box in Aqua L&F. This is because, as previously mentioned, the button's visual size can't change. If the arrow button's size is increased, space will be dedicated for the button in its container and the button will function if clicked within that space but the button would still appear to be the same size (which would be too small for larger text fields). So, the text field will not resize in height according to the font and the font would remain the larger font size of 30 in this example. This requires me to override the rectangle calculation method and update the logic for an editable text field of varying font sizes to correctly center the text field to be aligned with the arrow button. |
midHeight = 0; | ||
} | ||
|
||
if(comboBox.getComponentOrientation().isLeftToRight()) { |
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.
Let's add a space after if
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.
Fixed.
@@ -454,6 +454,32 @@ protected LayoutManager createLayoutManager() { | |||
} | |||
|
|||
class AquaComboBoxLayoutManager extends BasicComboBoxUI.ComboBoxLayoutManager { | |||
protected Rectangle rectangleForCurrentValue() { | |||
System.out.println("rectForCurrentValue NEW: " + comboBox.getHeight()); |
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.
Missed removing print statement :)
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.
Fixed. Thanks for catching that. I had a lot of comments to clean up after testing and this one slipped through.
protected Rectangle rectangleForCurrentValue() { | ||
System.out.println("rectForCurrentValue NEW: " + comboBox.getHeight()); | ||
int width = comboBox.getWidth(); | ||
int height = 21; |
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.
Is this a Aqua LAF constraint on max height of text-field?
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.
This height limitation is set to match the appearance of a non-oversized font in an editable JComboBox. I tested different values, and this value matches the appearance of an editable JComboBox when the AquaLookAndFeel control font is used.
The reason for overriding this method is to set this max height and condense the logic for the editor rectangle values. Previously, this class hard coded adjustments for the width and height values of the editor rectangle in layoutContainer when editor != null. This occurs right after this rectangleForCurrentValue is called, and this method is only used to calculate the rectangle position. So, overriding this method makes more sense since it does exactly that for Aqua L&F values specifically.
I am not sure if this is correct approach... So, assuming it's a issue, I think I see that we call AquaCombobBoxButton with Then it seems this painter.paint() which calls AquaPainter.paintFromSingleCachedImage() which calls MultiResolutionCachedImage to create a MRI maybe is not creating proper MRI image as per the given arrowbutton size. Maybe non-editable combobox can have "single cached image" to have single-sized arrowbutton, but it may not be correct for editable combobox where font size can be changed |
The best documentation I have is the webpage for pull-down buttons here: There's no text describing the behavior, but the image shows a bracket and lines with arrows on each end to show variable width of a pull-down button. However, for height, the bracket has no arrows, which indicate that the height is fixed. I'm currently looking at the MRI image issued, but that image combined with the behavior of non-editable comboboxes (even with larger fonts) led me to believe this approach was acceptable. |
Tested on Mac 12.3. The editable combobox looks quite close to the non editable one.
Just a thought: As @prsadhuk suggested earlier, carrying forward the focus ring style & thickness of the button over to the textfield might help in giving the editable combobox (textfield + button) a unified look when it has focus. Minor changes: |
Updated the copyright and text. For the border, I brought this topic up in previous talks and it was noted that the current appearance is sufficient, at least for now. The editable combobox uses the default textfield's focusborder and an additional issue can be created for updating the focus border to match the button's. |
Yes, JDK-8023912... |
I believe the question regarding font sizes was already sent to Apple last week. I can definitely add it to my ever-growing list of questions to Apple, but I was advised to keep this question to Apple focused on this particular issue. |
Through Phil, Apple has confirmed that the height of the JComboBox should be fixed. The reason being that the UI was designed around a control font size, and other UI such as button backgrounds and other related elements also have fixed height. The UI's height being resizable is possible, but is not intended for Aqua. So I believe this fix aligns with that philosophy and is an OK way of resolving the discrepancy between editable & non-editable JComboBoxes in Aqua L&F. |
} | ||
|
||
if (comboBox.getComponentOrientation().isLeftToRight()) { | ||
return new Rectangle(insets.left, insets.top + midHeight, |
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.
OK. Since Apple has confirmed combobox height shouldn't change with font size, we can have fixed height.
Only thing I guess, till we sort out JDK-8023912: [macosx] JComboBox RTL orientation problem
lets use LTR as it seems it might give a false impression that we support RTL when we dont even know if Apple supports it or not. Do you see any difference with combobox if you use LTR code vs RTL code with RTL testcase present in the above JBS? I dont in my BigSur.
It will also be good to test it out in non-retina display to see if this "22" height is being shown ok there.
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 don't see a difference either but was following the same logic as used in BasicComboBoxUI. I can remove the LTR vs RTL logic until the other issue is resolved if needed.
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.
You can keep this for now...You can take in JDK-8023912 incase which I guess needs a followup question to Apple.
|
||
frame = new JFrame(); | ||
frame.getContentPane().add(panel); | ||
frame.setVisible(true); |
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.
@DamonGuy To avoid flickering of the test frame move frame.setVisible(true)
after PassFailJFrame.positionTestWindow()
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.
Updated. Thanks, will note for the future.
@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 694 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. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@prsadhuk) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
/integrate |
@prsadhuk Could you sponsor this PR? |
/sponsor |
Going to push as commit 8082c24.
Your commit was automatically rebased without conflicts. |
When a JComboBox is editable, the button segment of the combo box is misaligned vertically and has a different height. This change fixes these issues and adds a manual test that checks the appearance of an editable and non-editable JComboBox.
One of the discussions revolving this issue is the native macOS appearance of editable JComboBoxes. After looking through native macOS apps, the only one found is in System Preferences > Date & Time. The problem here is that the native equivalent found here uses a blue button with a single down arrow as the button's symbol. The current swing implementation uses a white button with an up & down arrow symbol for the button. A JRS widget button that has this blue button with a single downward arrow exists but does not support text fields.
As such, I believe the best fix for this issue is to mainly fix the alignment and sizing issue. I looked through Apple's documentation for these UI elements but editable JComboBoxes aren't specifically listed anywhere. Similarly, there's barely any editable JComboBoxes used in native mac apps (only the date & time). So, I don't think it's a major issue if JComboBox does not exactly match the example found in Date & Time.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/9473/head:pull/9473
$ git checkout pull/9473
Update a local copy of the PR:
$ git checkout pull/9473
$ git pull https://git.openjdk.org/jdk pull/9473/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 9473
View PR using the GUI difftool:
$ git pr show -t 9473
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/9473.diff