Skip to content

Commit

Permalink
8054572: [macosx] JComboBox paints the border incorrectly
Browse files Browse the repository at this point in the history
Backport-of: 8082c24a0df3f4861ea391266bdfe6cdd1a77bab
  • Loading branch information
GoeLin committed Dec 7, 2023
1 parent 5217b07 commit 644a430
Showing 1 changed file with 26 additions and 3 deletions.
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 @@ -453,6 +453,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 @@ -476,8 +501,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

1 comment on commit 644a430

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.