mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-08 06:50:56 +03:00
TextField: added styles for buttons and toolbars in leading and trailing components (smaller margins/insets, better hover/pressed/selected colors)
This commit is contained in:
@@ -364,6 +364,12 @@ class UIDefaultsLoader
|
|||||||
if( resultValueType == null )
|
if( resultValueType == null )
|
||||||
resultValueType = tempResultValueType;
|
resultValueType = tempResultValueType;
|
||||||
|
|
||||||
|
// do not parse styles here
|
||||||
|
if( key.startsWith( "[style]" ) ) {
|
||||||
|
resultValueType[0] = ValueType.STRING;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
value = value.trim();
|
value = value.trim();
|
||||||
|
|
||||||
// null
|
// null
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import static com.formdev.flatlaf.util.UIScale.scale;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
|
import java.awt.Cursor;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.FontMetrics;
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
@@ -35,10 +36,13 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
|
import javax.swing.JButton;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JSpinner;
|
import javax.swing.JSpinner;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.JToggleButton;
|
||||||
|
import javax.swing.JToolBar;
|
||||||
import javax.swing.LookAndFeel;
|
import javax.swing.LookAndFeel;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
@@ -556,19 +560,19 @@ debug*/
|
|||||||
// remove width of leading/trailing components
|
// remove width of leading/trailing components
|
||||||
JComponent leftComponent = ltr ? leadingComponent : trailingComponent;
|
JComponent leftComponent = ltr ? leadingComponent : trailingComponent;
|
||||||
JComponent rightComponent = ltr ? trailingComponent : leadingComponent;
|
JComponent rightComponent = ltr ? trailingComponent : leadingComponent;
|
||||||
if( leftComponent != null ) {
|
boolean leftVisible = leftComponent != null && leftComponent.isVisible();
|
||||||
|
boolean rightVisible = rightComponent != null && rightComponent.isVisible();
|
||||||
|
if( leftVisible ) {
|
||||||
int w = leftComponent.getPreferredSize().width;
|
int w = leftComponent.getPreferredSize().width;
|
||||||
r.x += w;
|
r.x += w;
|
||||||
r.width -= w;
|
r.width -= w;
|
||||||
}
|
}
|
||||||
if( rightComponent != null )
|
if( rightVisible )
|
||||||
r.width -= rightComponent.getPreferredSize().width;
|
r.width -= rightComponent.getPreferredSize().width;
|
||||||
|
|
||||||
// if a leading/trailing icons (or components) are shown, then the left/right margins are reduced
|
// if a leading/trailing icons (or components) are shown, then the left/right margins are reduced
|
||||||
// to the top margin, which places the icon nicely centered on left/right side
|
// to the top margin, which places the icon nicely centered on left/right side
|
||||||
if( (ltr ? hasLeadingIcon() : hasTrailingIcon()) ||
|
if( leftVisible || (ltr ? hasLeadingIcon() : hasTrailingIcon()) ) {
|
||||||
(leftComponent != null && leftComponent.isVisible()) )
|
|
||||||
{
|
|
||||||
// reduce left margin
|
// reduce left margin
|
||||||
Insets margin = getComponent().getMargin();
|
Insets margin = getComponent().getMargin();
|
||||||
int newLeftMargin = Math.min( margin.left, margin.top );
|
int newLeftMargin = Math.min( margin.left, margin.top );
|
||||||
@@ -578,9 +582,7 @@ debug*/
|
|||||||
r.width += diff;
|
r.width += diff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( (ltr ? hasTrailingIcon() : hasLeadingIcon()) ||
|
if( rightVisible || (ltr ? hasTrailingIcon() : hasLeadingIcon()) ) {
|
||||||
(rightComponent != null && rightComponent.isVisible()) )
|
|
||||||
{
|
|
||||||
// reduce right margin
|
// reduce right margin
|
||||||
Insets margin = getComponent().getMargin();
|
Insets margin = getComponent().getMargin();
|
||||||
int newRightMargin = Math.min( margin.right, margin.top );
|
int newRightMargin = Math.min( margin.right, margin.top );
|
||||||
@@ -636,6 +638,7 @@ debug*/
|
|||||||
JTextComponent c = getComponent();
|
JTextComponent c = getComponent();
|
||||||
leadingComponent = clientProperty( c, TEXT_FIELD_LEADING_COMPONENT, null, JComponent.class );
|
leadingComponent = clientProperty( c, TEXT_FIELD_LEADING_COMPONENT, null, JComponent.class );
|
||||||
if( leadingComponent != null ) {
|
if( leadingComponent != null ) {
|
||||||
|
prepareLeadingOrTrailingComponent( leadingComponent );
|
||||||
installLayout();
|
installLayout();
|
||||||
c.add( leadingComponent );
|
c.add( leadingComponent );
|
||||||
}
|
}
|
||||||
@@ -646,6 +649,7 @@ debug*/
|
|||||||
JTextComponent c = getComponent();
|
JTextComponent c = getComponent();
|
||||||
trailingComponent = clientProperty( c, TEXT_FIELD_TRAILING_COMPONENT, null, JComponent.class );
|
trailingComponent = clientProperty( c, TEXT_FIELD_TRAILING_COMPONENT, null, JComponent.class );
|
||||||
if( trailingComponent != null ) {
|
if( trailingComponent != null ) {
|
||||||
|
prepareLeadingOrTrailingComponent( trailingComponent );
|
||||||
installLayout();
|
installLayout();
|
||||||
c.add( trailingComponent );
|
c.add( trailingComponent );
|
||||||
}
|
}
|
||||||
@@ -667,6 +671,21 @@ debug*/
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2 */
|
||||||
|
protected void prepareLeadingOrTrailingComponent( JComponent c ) {
|
||||||
|
c.putClientProperty( STYLE_CLASS, "inTextField" );
|
||||||
|
c.setCursor( Cursor.getDefaultCursor() );
|
||||||
|
|
||||||
|
if( c instanceof JButton || c instanceof JToggleButton )
|
||||||
|
c.putClientProperty( BUTTON_TYPE, BUTTON_TYPE_TOOLBAR_BUTTON );
|
||||||
|
else if( c instanceof JToolBar ) {
|
||||||
|
for( Component child : c.getComponents() ) {
|
||||||
|
if( child instanceof JComponent )
|
||||||
|
((JComponent)child).putClientProperty( STYLE_CLASS, "inTextField" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void installLayout() {
|
private void installLayout() {
|
||||||
JTextComponent c = getComponent();
|
JTextComponent c = getComponent();
|
||||||
LayoutManager oldLayout = c.getLayout();
|
LayoutManager oldLayout = c.getLayout();
|
||||||
|
|||||||
@@ -355,3 +355,19 @@ ToolTip.background = shade(@background,50%)
|
|||||||
#---- Tree ----
|
#---- Tree ----
|
||||||
|
|
||||||
Tree.hash = lighten($Tree.background,5%)
|
Tree.hash = lighten($Tree.background,5%)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#---- Styles ------------------------------------------------------------------
|
||||||
|
|
||||||
|
#---- inTextField ----
|
||||||
|
# for leading/trailing components in text fields
|
||||||
|
|
||||||
|
[style]Button.inTextField = \
|
||||||
|
focusable: false; \
|
||||||
|
toolbar.margin: 1,1,1,1; \
|
||||||
|
toolbar.spacingInsets: 1,1,1,1; \
|
||||||
|
background: $TextField.background; \
|
||||||
|
toolbar.hoverBackground: lighten($TextField.background,4%,derived); \
|
||||||
|
toolbar.pressedBackground: lighten($TextField.background,6%,derived); \
|
||||||
|
toolbar.selectedBackground: lighten($TextField.background,12%,derived)
|
||||||
|
|||||||
@@ -227,6 +227,7 @@ Button.defaultButtonFollowsFocus = false
|
|||||||
Button.borderWidth = 1
|
Button.borderWidth = 1
|
||||||
Button.default.borderWidth = 1
|
Button.default.borderWidth = 1
|
||||||
|
|
||||||
|
# for buttons in toolbars
|
||||||
Button.toolbar.margin = 3,3,3,3
|
Button.toolbar.margin = 3,3,3,3
|
||||||
Button.toolbar.spacingInsets = 1,2,1,2
|
Button.toolbar.spacingInsets = 1,2,1,2
|
||||||
|
|
||||||
@@ -889,3 +890,20 @@ Tree.icon.collapsedColor = @icon
|
|||||||
Tree.icon.leafColor = @icon
|
Tree.icon.leafColor = @icon
|
||||||
Tree.icon.closedColor = @icon
|
Tree.icon.closedColor = @icon
|
||||||
Tree.icon.openColor = @icon
|
Tree.icon.openColor = @icon
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#---- Styles ------------------------------------------------------------------
|
||||||
|
|
||||||
|
#---- inTextField ----
|
||||||
|
# for leading/trailing components in text fields
|
||||||
|
|
||||||
|
[style]ToggleButton.inTextField = $[style]Button.inTextField
|
||||||
|
|
||||||
|
[style]ToolBar.inTextField = \
|
||||||
|
floatable: false; \
|
||||||
|
opaque: false; \
|
||||||
|
borderMargins: 0,0,0,0
|
||||||
|
|
||||||
|
[style]ToolBarSeparator.inTextField = \
|
||||||
|
separatorWidth: 3
|
||||||
|
|||||||
@@ -362,3 +362,19 @@ ToolTip.background = lighten(@background,3%)
|
|||||||
#---- Tree ----
|
#---- Tree ----
|
||||||
|
|
||||||
Tree.hash = darken($Tree.background,10%)
|
Tree.hash = darken($Tree.background,10%)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#---- Styles ------------------------------------------------------------------
|
||||||
|
|
||||||
|
#---- inTextField ----
|
||||||
|
# for leading/trailing components in text fields
|
||||||
|
|
||||||
|
[style]Button.inTextField = \
|
||||||
|
focusable: false; \
|
||||||
|
toolbar.margin: 1,1,1,1; \
|
||||||
|
toolbar.spacingInsets: 1,1,1,1; \
|
||||||
|
background: $TextField.background; \
|
||||||
|
toolbar.hoverBackground: darken($TextField.background,4%,derived); \
|
||||||
|
toolbar.pressedBackground: darken($TextField.background,8%,derived); \
|
||||||
|
toolbar.selectedBackground: darken($TextField.background,12%,derived)
|
||||||
|
|||||||
@@ -1419,6 +1419,26 @@ ViewportUI com.formdev.flatlaf.ui.FlatViewportUI
|
|||||||
[style].small font: $small.font
|
[style].small font: $small.font
|
||||||
|
|
||||||
|
|
||||||
|
#---- [style]Button ----
|
||||||
|
|
||||||
|
[style]Button.inTextField focusable: false; toolbar.margin: 1,1,1,1; toolbar.spacingInsets: 1,1,1,1; background: $TextField.background; toolbar.hoverBackground: lighten($TextField.background,4%,derived); toolbar.pressedBackground: lighten($TextField.background,6%,derived); toolbar.selectedBackground: lighten($TextField.background,12%,derived)
|
||||||
|
|
||||||
|
|
||||||
|
#---- [style]ToggleButton ----
|
||||||
|
|
||||||
|
[style]ToggleButton.inTextField focusable: false; toolbar.margin: 1,1,1,1; toolbar.spacingInsets: 1,1,1,1; background: $TextField.background; toolbar.hoverBackground: lighten($TextField.background,4%,derived); toolbar.pressedBackground: lighten($TextField.background,6%,derived); toolbar.selectedBackground: lighten($TextField.background,12%,derived)
|
||||||
|
|
||||||
|
|
||||||
|
#---- [style]ToolBar ----
|
||||||
|
|
||||||
|
[style]ToolBar.inTextField floatable: false; opaque: false; borderMargins: 0,0,0,0
|
||||||
|
|
||||||
|
|
||||||
|
#---- [style]ToolBarSeparator ----
|
||||||
|
|
||||||
|
[style]ToolBarSeparator.inTextField separatorWidth: 3
|
||||||
|
|
||||||
|
|
||||||
#---- ----
|
#---- ----
|
||||||
|
|
||||||
activeCaption #434e60 HSL 217 18 32 javax.swing.plaf.ColorUIResource [UI]
|
activeCaption #434e60 HSL 217 18 32 javax.swing.plaf.ColorUIResource [UI]
|
||||||
|
|||||||
@@ -1424,6 +1424,26 @@ ViewportUI com.formdev.flatlaf.ui.FlatViewportUI
|
|||||||
[style].small font: $small.font
|
[style].small font: $small.font
|
||||||
|
|
||||||
|
|
||||||
|
#---- [style]Button ----
|
||||||
|
|
||||||
|
[style]Button.inTextField focusable: false; toolbar.margin: 1,1,1,1; toolbar.spacingInsets: 1,1,1,1; background: $TextField.background; toolbar.hoverBackground: darken($TextField.background,4%,derived); toolbar.pressedBackground: darken($TextField.background,8%,derived); toolbar.selectedBackground: darken($TextField.background,12%,derived)
|
||||||
|
|
||||||
|
|
||||||
|
#---- [style]ToggleButton ----
|
||||||
|
|
||||||
|
[style]ToggleButton.inTextField focusable: false; toolbar.margin: 1,1,1,1; toolbar.spacingInsets: 1,1,1,1; background: $TextField.background; toolbar.hoverBackground: darken($TextField.background,4%,derived); toolbar.pressedBackground: darken($TextField.background,8%,derived); toolbar.selectedBackground: darken($TextField.background,12%,derived)
|
||||||
|
|
||||||
|
|
||||||
|
#---- [style]ToolBar ----
|
||||||
|
|
||||||
|
[style]ToolBar.inTextField floatable: false; opaque: false; borderMargins: 0,0,0,0
|
||||||
|
|
||||||
|
|
||||||
|
#---- [style]ToolBarSeparator ----
|
||||||
|
|
||||||
|
[style]ToolBarSeparator.inTextField separatorWidth: 3
|
||||||
|
|
||||||
|
|
||||||
#---- ----
|
#---- ----
|
||||||
|
|
||||||
activeCaption #99b4d1 HSL 211 38 71 javax.swing.plaf.ColorUIResource [UI]
|
activeCaption #99b4d1 HSL 211 38 71 javax.swing.plaf.ColorUIResource [UI]
|
||||||
|
|||||||
@@ -1437,6 +1437,26 @@ ViewportUI com.formdev.flatlaf.ui.FlatViewportUI
|
|||||||
[style].small font: $small.font
|
[style].small font: $small.font
|
||||||
|
|
||||||
|
|
||||||
|
#---- [style]Button ----
|
||||||
|
|
||||||
|
[style]Button.inTextField focusable: false; toolbar.margin: 1,1,1,1; toolbar.spacingInsets: 1,1,1,1
|
||||||
|
|
||||||
|
|
||||||
|
#---- [style]ToggleButton ----
|
||||||
|
|
||||||
|
[style]ToggleButton.inTextField focusable: false; toolbar.margin: 1,1,1,1; toolbar.spacingInsets: 1,1,1,1
|
||||||
|
|
||||||
|
|
||||||
|
#---- [style]ToolBar ----
|
||||||
|
|
||||||
|
[style]ToolBar.inTextField floatable: false; opaque: false; borderMargins: 0,0,0,0
|
||||||
|
|
||||||
|
|
||||||
|
#---- [style]ToolBarSeparator ----
|
||||||
|
|
||||||
|
[style]ToolBarSeparator.inTextField separatorWidth: 3
|
||||||
|
|
||||||
|
|
||||||
#---- ----
|
#---- ----
|
||||||
|
|
||||||
activeCaption #99b4d1 HSL 211 38 71 javax.swing.plaf.ColorUIResource [UI]
|
activeCaption #99b4d1 HSL 211 38 71 javax.swing.plaf.ColorUIResource [UI]
|
||||||
|
|||||||
@@ -443,3 +443,15 @@ Tree.paintLines = true
|
|||||||
Tree.hash = #f00
|
Tree.hash = #f00
|
||||||
Tree.editorBorder = 1,1,1,1,#f00
|
Tree.editorBorder = 1,1,1,1,#f00
|
||||||
Tree.editorBorderSelectionColor = #00f
|
Tree.editorBorderSelectionColor = #00f
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#---- Styles ------------------------------------------------------------------
|
||||||
|
|
||||||
|
#---- inTextField ----
|
||||||
|
# for leading/trailing components in text fields
|
||||||
|
|
||||||
|
[style]Button.inTextField = \
|
||||||
|
focusable: false; \
|
||||||
|
toolbar.margin: 1,1,1,1; \
|
||||||
|
toolbar.spacingInsets: 1,1,1,1
|
||||||
|
|||||||
@@ -1115,6 +1115,10 @@ ViewportUI
|
|||||||
[style].monospaced
|
[style].monospaced
|
||||||
[style].semibold
|
[style].semibold
|
||||||
[style].small
|
[style].small
|
||||||
|
[style]Button.inTextField
|
||||||
|
[style]ToggleButton.inTextField
|
||||||
|
[style]ToolBar.inTextField
|
||||||
|
[style]ToolBarSeparator.inTextField
|
||||||
activeCaption
|
activeCaption
|
||||||
activeCaptionBorder
|
activeCaptionBorder
|
||||||
activeCaptionText
|
activeCaptionText
|
||||||
|
|||||||
Reference in New Issue
Block a user