Skip to content
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 #2020

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/java.desktop/macosx/classes/com/apple/laf/AquaComboBoxUI.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -454,6 +454,31 @@ protected LayoutManager createLayoutManager() {
}

class AquaComboBoxLayoutManager extends BasicComboBoxUI.ComboBoxLayoutManager {
protected Rectangle rectangleForCurrentValue() {
int width = comboBox.getWidth();
int height = 22;
Insets insets = getInsets();
int buttonSize = height - (insets.top + insets.bottom);
if ( arrowButton != null ) {
buttonSize = arrowButton.getWidth();
}
int midHeight = (comboBox.getHeight() - height - (insets.top + insets.bottom)) / 2 - 1;
if (midHeight < 0) {
midHeight = 0;
}

if (comboBox.getComponentOrientation().isLeftToRight()) {
return new Rectangle(insets.left, insets.top + midHeight,
width - (insets.left + insets.right + buttonSize) + 4,
height - (insets.top + insets.bottom));
}
else {
return new Rectangle(insets.left + buttonSize, insets.top + midHeight,
width - (insets.left + insets.right + buttonSize) + 4,
height - (insets.top + insets.bottom));
}
}

public void layoutContainer(final Container parent) {
if (arrowButton != null && !comboBox.isEditable()) {
final Insets insets = comboBox.getInsets();
Expand All @@ -477,8 +502,6 @@ public void layoutContainer(final Container parent) {

if (editor != null) {
final Rectangle editorRect = rectangleForCurrentValue();
editorRect.width += 4;
editorRect.height += 1;
editor.setBounds(editorRect);
}
}
Expand Down