mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
Button, CheckBox, RadioButton and ToggleButton: do not paint focus indicator if AbstractButton.isFocusPainted() returns false
This commit is contained in:
@@ -18,6 +18,8 @@ FlatLaf Change Log
|
||||
`Spinner.buttonStyle` to `button` (default) or `none`).
|
||||
- TableHeader: Support top/bottom/left positioned sort arrow when using
|
||||
[Glazed Lists](https://github.com/glazedlists/glazedlists). (issue #113)
|
||||
- Button, CheckBox, RadioButton and ToggleButton: Do not paint focus indicator
|
||||
if `AbstractButton.isFocusPainted()` returns `false`.
|
||||
- Fixed/improved vertical position of text when scaled on HiDPI screens on
|
||||
Windows.
|
||||
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -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 ) );
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -80,6 +80,15 @@ public class FlatComponentsTest
|
||||
}
|
||||
}
|
||||
|
||||
private void focusPaintedChanged() {
|
||||
boolean focusPainted = focusPaintedCheckBox.isSelected();
|
||||
|
||||
for( Component c : getComponents() ) {
|
||||
if( c instanceof AbstractButton )
|
||||
((AbstractButton)c).setFocusPainted( focusPainted );
|
||||
}
|
||||
}
|
||||
|
||||
private void roundRectChanged() {
|
||||
Boolean roundRect = roundRectCheckBox.isSelected() ? true : null;
|
||||
|
||||
@@ -262,6 +271,7 @@ public class FlatComponentsTest
|
||||
warningOutlineRadioButton = new JRadioButton();
|
||||
magentaOutlineRadioButton = new JRadioButton();
|
||||
magentaCyanOutlineRadioButton = new JRadioButton();
|
||||
focusPaintedCheckBox = new JCheckBox();
|
||||
JLabel scrollBarLabel = new JLabel();
|
||||
JScrollBar scrollBar1 = new JScrollBar();
|
||||
JScrollBar scrollBar4 = new JScrollBar();
|
||||
@@ -1065,6 +1075,7 @@ public class FlatComponentsTest
|
||||
// rows
|
||||
"[]" +
|
||||
"[]" +
|
||||
"[]" +
|
||||
"[]"));
|
||||
|
||||
//---- buttonTypeComboBox ----
|
||||
@@ -1125,7 +1136,13 @@ public class FlatComponentsTest
|
||||
magentaCyanOutlineRadioButton.addActionListener(e -> outlineChanged());
|
||||
panel4.add(magentaCyanOutlineRadioButton);
|
||||
}
|
||||
panel5.add(panel4, "cell 0 2");
|
||||
panel5.add(panel4, "cell 0 2 1 2");
|
||||
|
||||
//---- focusPaintedCheckBox ----
|
||||
focusPaintedCheckBox.setText("focusPainted");
|
||||
focusPaintedCheckBox.setSelected(true);
|
||||
focusPaintedCheckBox.addActionListener(e -> focusPaintedChanged());
|
||||
panel5.add(focusPaintedCheckBox, "cell 1 2");
|
||||
}
|
||||
add(panel5, "cell 5 13 2 10,grow");
|
||||
|
||||
@@ -1366,6 +1383,7 @@ public class FlatComponentsTest
|
||||
private JRadioButton warningOutlineRadioButton;
|
||||
private JRadioButton magentaOutlineRadioButton;
|
||||
private JRadioButton magentaCyanOutlineRadioButton;
|
||||
private JCheckBox focusPaintedCheckBox;
|
||||
private JSlider slider3;
|
||||
private JProgressBar progressBar1;
|
||||
private JProgressBar progressBar2;
|
||||
|
||||
@@ -940,7 +940,7 @@ new FormModel {
|
||||
} )
|
||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||
"$columnConstraints": "[][]"
|
||||
"$rowConstraints": "[][][]"
|
||||
"$rowConstraints": "[][][][]"
|
||||
"$layoutConstraints": "ltr,insets dialog,hidemode 3"
|
||||
} ) {
|
||||
name: "panel5"
|
||||
@@ -1045,7 +1045,18 @@ new FormModel {
|
||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "outlineChanged", false ) )
|
||||
} )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 2"
|
||||
"value": "cell 0 2 1 2"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||
name: "focusPaintedCheckBox"
|
||||
"text": "focusPainted"
|
||||
"selected": true
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "focusPaintedChanged", false ) )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 2"
|
||||
} )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 5 13 2 10,grow"
|
||||
|
||||
Reference in New Issue
Block a user