ComboBox, Spinner and TextField: support round border style (set client property JComponent.roundRect to true)

This commit is contained in:
Karl Tauber
2020-05-15 13:38:45 +02:00
parent 26c77b3118
commit 83fdeb7e0c
12 changed files with 107 additions and 8 deletions

View File

@@ -103,6 +103,15 @@ public interface FlatClientProperties
*/
String MINIMUM_HEIGHT = "JComponent.minimumHeight";
/**
* Paint the component with round edges.
* <p>
* <strong>Components</strong> {@link javax.swing.JComboBox}, {@link javax.swing.JSpinner},
* {@link javax.swing.JTextField}, {@link javax.swing.JFormattedTextField} and {@link javax.swing.JPasswordField}
* <strong>Value type</strong> {@link java.lang.Boolean}
*/
String COMPONENT_ROUND_RECT = "JComponent.roundRect";
/**
* Specifies whether a drop shadow is painted if the component is shown in a popup
* or if the component is the owner of another component that is shown in a popup.

View File

@@ -208,6 +208,10 @@ public class FlatButtonUI
case MINIMUM_HEIGHT:
b.revalidate();
break;
case BUTTON_TYPE:
b.repaint();
break;
}
}

View File

@@ -243,6 +243,8 @@ public class FlatComboBoxUI
editor.applyComponentOrientation( o );
} else if( editor != null && FlatClientProperties.PLACEHOLDER_TEXT.equals( propertyName ) )
editor.repaint();
else if( FlatClientProperties.COMPONENT_ROUND_RECT.equals( propertyName ) )
comboBox.repaint();
}
};
}

View File

@@ -34,7 +34,6 @@ import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicPasswordFieldUI;
import javax.swing.text.Caret;
import javax.swing.text.JTextComponent;
import com.formdev.flatlaf.FlatClientProperties;
/**
* Provides the Flat LaF UI delegate for {@link javax.swing.JPasswordField}.
@@ -147,9 +146,7 @@ public class FlatPasswordFieldUI
@Override
protected void propertyChange( PropertyChangeEvent e ) {
super.propertyChange( e );
if( FlatClientProperties.PLACEHOLDER_TEXT.equals( e.getPropertyName() ) )
getComponent().repaint();
FlatTextFieldUI.propertyChange( getComponent(), e );
}
@Override

View File

@@ -33,6 +33,6 @@ public class FlatRoundBorder
@Override
protected int getArc( Component c ) {
return arc;
return FlatUIUtils.isRoundRect( c ) ? Short.MAX_VALUE : arc;
}
}

View File

@@ -40,6 +40,7 @@ import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicSpinnerUI;
import com.formdev.flatlaf.FlatClientProperties;
/**
* Provides the Flat LaF UI delegate for {@link javax.swing.JSpinner}.
@@ -394,6 +395,10 @@ public class FlatSpinnerUI
case "enabled":
updateEditorColors();
break;
case FlatClientProperties.COMPONENT_ROUND_RECT:
spinner.repaint();
break;
}
}
}

View File

@@ -33,6 +33,6 @@ public class FlatTextBorder
@Override
protected int getArc( Component c ) {
return arc;
return FlatUIUtils.isRoundRect( c ) ? Short.MAX_VALUE : arc;
}
}

View File

@@ -127,9 +127,16 @@ public class FlatTextFieldUI
@Override
protected void propertyChange( PropertyChangeEvent e ) {
super.propertyChange( e );
propertyChange( getComponent(), e );
}
if( FlatClientProperties.PLACEHOLDER_TEXT.equals( e.getPropertyName() ) )
getComponent().repaint();
static void propertyChange( JTextComponent c, PropertyChangeEvent e ) {
switch( e.getPropertyName() ) {
case FlatClientProperties.PLACEHOLDER_TEXT:
case FlatClientProperties.COMPONENT_ROUND_RECT:
c.repaint();
break;
}
}
@Override

View File

@@ -143,6 +143,11 @@ public class FlatUIUtils
return (KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner() == c);
}
public static boolean isRoundRect( Component c ) {
return c instanceof JComponent && FlatClientProperties.clientPropertyBoolean(
(JComponent) c, FlatClientProperties.COMPONENT_ROUND_RECT, false );
}
/**
* Returns the scaled thickness of the outer focus border for the given component.
*/