Button, CheckBox, RadioButton and ToggleButton: do not paint focus indicator if AbstractButton.isFocusPainted() returns false

This commit is contained in:
Karl Tauber
2020-06-24 16:45:41 +02:00
parent 71e61f8f27
commit c25ff57b61
7 changed files with 47 additions and 7 deletions

View File

@@ -135,7 +135,7 @@ public class FlatCheckBoxIcon
boolean isFocused = FlatUIUtils.isPermanentFocusOwner( c );
// paint focused border
if( isFocused && focusWidth > 0 ) {
if( isFocused && focusWidth > 0 && FlatButtonUI.isFocusPainted( c ) ) {
g2.setColor( focusColor );
paintFocusBorder( g2 );
}

View File

@@ -85,7 +85,7 @@ public class FlatHelpButtonIcon
boolean focused = FlatUIUtils.isPermanentFocusOwner( c );
// paint focused border
if( focused ) {
if( focused && FlatButtonUI.isFocusPainted( c ) ) {
g2.setColor( focusColor );
g2.fill( new Ellipse2D.Float( 0.5f, 0.5f, iconSize - 1, iconSize - 1 ) );
}

View File

@@ -81,6 +81,11 @@ public class FlatButtonBorder
return FlatButtonUI.isDefaultButton( c ) ? defaultFocusColor : super.getFocusColor( c );
}
@Override
protected boolean isFocused( Component c ) {
return FlatButtonUI.isFocusPainted( c ) && super.isFocused( c );
}
@Override
protected Paint getBorderColor( Component c ) {
boolean def = FlatButtonUI.isDefaultButton( c );

View File

@@ -229,6 +229,10 @@ public class FlatButtonUI
return !(c instanceof AbstractButton) || ((AbstractButton)c).isContentAreaFilled();
}
public static boolean isFocusPainted( Component c ) {
return !(c instanceof AbstractButton) || ((AbstractButton)c).isFocusPainted();
}
static boolean isDefaultButton( Component c ) {
return c instanceof JButton && ((JButton)c).isDefaultButton();
}
@@ -315,7 +319,7 @@ public class FlatButtonUI
// paint shadow
Color shadowColor = def ? defaultShadowColor : this.shadowColor;
if( !isToolBarButton && shadowColor != null && shadowWidth > 0 && focusWidth > 0 &&
!FlatUIUtils.isPermanentFocusOwner( c ) && c.isEnabled() )
!(isFocusPainted( c ) && FlatUIUtils.isPermanentFocusOwner( c )) && c.isEnabled() )
{
g2.setColor( shadowColor );
g2.fill( new RoundRectangle2D.Float( focusWidth, focusWidth + UIScale.scale( (float) shadowWidth ),
@@ -421,7 +425,7 @@ public class FlatButtonUI
if( hoverColor != null && b != null && b.getModel().isRollover() )
return hoverColor;
if( focusedColor != null && FlatUIUtils.isPermanentFocusOwner( c ) )
if( focusedColor != null && isFocusPainted( c ) && FlatUIUtils.isPermanentFocusOwner( c ) )
return focusedColor;
return enabledColor;