ComboBox and Spinner: move arrow slightly to the left if round borders are used on the component

This commit is contained in:
Karl Tauber
2020-05-18 23:26:34 +02:00
parent ddf9ed06ab
commit 16d51fe6b4
2 changed files with 11 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.util.UIScale.scale;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
@@ -26,6 +27,7 @@ import java.awt.Shape;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.Path2D;
import javax.swing.JComponent;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicArrowButton;
@@ -152,6 +154,11 @@ public class FlatArrowButton
if( y + rh >= height && y > 0 )
y--;
// move arrow for round borders
Container parent = getParent();
if( parent instanceof JComponent && FlatUIUtils.hasRoundBorder( (JComponent) parent ) )
x -= scale( parent.getComponentOrientation().isLeftToRight() ? 1 : -1 );
// paint arrow
g.setColor( enabled
? (isHover() && hoverForeground != null ? hoverForeground : foreground)

View File

@@ -168,6 +168,10 @@ public class FlatUIUtils
: 0;
}
public static boolean hasRoundBorder( JComponent c ) {
return getBorderArc( c ) >= c.getHeight();
}
/**
* Sets rendering hints used for painting.
*/