Package com.formdev.flatlaf.ui
Class FlatButtonUI
- java.lang.Object
-
- javax.swing.plaf.ComponentUI
-
- javax.swing.plaf.ButtonUI
-
- javax.swing.plaf.basic.BasicButtonUI
-
- com.formdev.flatlaf.ui.FlatButtonUI
-
- All Implemented Interfaces:
FlatStylingSupport.StyleableUI
- Direct Known Subclasses:
FlatToggleButtonUI
public class FlatButtonUI extends javax.swing.plaf.basic.BasicButtonUI implements FlatStylingSupport.StyleableUI
Provides the Flat LaF UI delegate forJButton
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
FlatButtonUI.FlatButtonListener
-
Field Summary
Fields Modifier and Type Field Description protected java.awt.Color
background
private java.util.concurrent.atomic.AtomicBoolean
borderShared
protected java.lang.String
buttonType
protected java.awt.Color
defaultBackground
protected boolean
defaultBoldText
protected java.awt.Color
defaultEndBackground
protected java.awt.Color
defaultFocusedBackground
protected java.awt.Color
defaultFocusedForeground
protected java.awt.Color
defaultForeground
protected java.awt.Color
defaultHoverBackground
protected java.awt.Color
defaultHoverForeground
private java.awt.Insets
defaultMargin
protected java.awt.Color
defaultPressedBackground
protected java.awt.Color
defaultPressedForeground
private boolean
defaults_initialized
protected java.awt.Color
defaultShadowColor
protected java.awt.Color
disabledBackground
protected java.awt.Color
disabledSelectedBackground
protected java.awt.Color
disabledSelectedForeground
protected java.awt.Color
disabledText
protected java.awt.Color
endBackground
protected java.awt.Color
focusedBackground
protected java.awt.Color
focusedForeground
protected java.awt.Color
foreground
private javax.swing.Icon
helpButtonIcon
private boolean
helpButtonIconShared
protected java.awt.Color
hoverBackground
protected java.awt.Color
hoverForeground
private static java.awt.Rectangle
iconR
protected int
iconTextGap
protected int
minimumHeight
protected int
minimumWidth
private java.util.Map<java.lang.String,java.lang.Object>
oldStyleValues
protected boolean
paintShadow
protected java.awt.Color
pressedBackground
protected java.awt.Color
pressedForeground
protected java.awt.Color
selectedBackground
protected java.awt.Color
selectedForeground
protected java.awt.Color
shadowColor
protected int
shadowWidth
private boolean
shared
protected boolean
squareSize
protected java.awt.Color
startBackground
private static java.awt.Rectangle
textR
protected java.awt.Color
toolbarDisabledSelectedBackground
protected java.awt.Color
toolbarDisabledSelectedForeground
protected java.awt.Color
toolbarHoverBackground
protected java.awt.Color
toolbarHoverForeground
protected java.awt.Color
toolbarPressedBackground
protected java.awt.Color
toolbarPressedForeground
protected java.awt.Color
toolbarSelectedBackground
protected java.awt.Color
toolbarSelectedForeground
(package private) static int
TYPE_OTHER
(package private) static int
TYPE_ROUND_RECT
(package private) static int
TYPE_SQUARE
private static java.awt.Rectangle
viewR
-
Constructor Summary
Constructors Modifier Constructor Description protected
FlatButtonUI(boolean shared)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
applyStyle(javax.swing.AbstractButton b, java.lang.Object style)
protected java.lang.Object
applyStyleProperty(javax.swing.AbstractButton b, java.lang.String key, java.lang.Object value)
static java.awt.Color
buttonStateColor(java.awt.Component c, java.awt.Color enabledColor, java.awt.Color disabledColor, java.awt.Color focusedColor, java.awt.Color hoverColor, java.awt.Color pressedColor)
protected javax.swing.plaf.basic.BasicButtonListener
createButtonListener(javax.swing.AbstractButton b)
static javax.swing.plaf.ComponentUI
createUI(javax.swing.JComponent c)
private int
defaultBoldPlainWidthDiff(javax.swing.JComponent c)
protected java.awt.Color
getBackground(javax.swing.JComponent c)
protected java.awt.Color
getBackgroundBase(javax.swing.JComponent c, boolean def)
int
getBaseline(javax.swing.JComponent c, int width, int height)
(package private) static int
getBaselineImpl(javax.swing.JComponent c, int width, int height)
Similar to BasicButtonUI.getBaseline(), but does not use zero insets for HTML text, which is done in BasicButtonUI.layout() since Java 19.(package private) static int
getButtonType(java.awt.Component c)
(package private) static java.lang.String
getButtonTypeStr(javax.swing.AbstractButton c)
protected java.awt.Color
getForeground(javax.swing.JComponent c)
protected java.awt.Color
getForegroundBase(javax.swing.JComponent c, boolean def)
java.awt.Dimension
getPreferredSize(javax.swing.JComponent c)
java.util.Map<java.lang.String,java.lang.Class<?>>
getStyleableInfos(javax.swing.JComponent c)
java.lang.Object
getStyleableValue(javax.swing.JComponent c, java.lang.String key)
(package private) java.lang.String
getStyleType()
private boolean
hasDefaultMargins(javax.swing.JComponent c)
protected void
installDefaults(javax.swing.AbstractButton b)
protected void
installStyle(javax.swing.AbstractButton b)
void
installUI(javax.swing.JComponent c)
private void
installUIImpl(javax.swing.JComponent c)
(package private) static boolean
isBorderlessButton(java.awt.Component c)
(package private) static boolean
isContentAreaFilled(java.awt.Component c)
protected boolean
isCustomBackground(java.awt.Color bg)
protected boolean
isCustomForeground(java.awt.Color fg)
(package private) static boolean
isDefaultButton(java.awt.Component c)
static boolean
isFocusPainted(java.awt.Component c)
(package private) static boolean
isHelpButton(java.awt.Component c)
(package private) static boolean
isIconOnlyOrSingleCharacterButton(java.awt.Component c)
Returns true if the button has an icon but no text, or it does not have an icon and the text is either "..." or one character.(package private) static boolean
isToolBarButton(java.awt.Component c)
private static java.lang.String
layout(javax.swing.AbstractButton b, java.awt.FontMetrics fm, int width, int height)
Similar to BasicButtonUI.layout(), but does not use zero insets for HTML text, which is done in BasicButtonUI.layout() since Java 19.void
paint(java.awt.Graphics g, javax.swing.JComponent c)
Similar to BasicButtonUI.paint(), but does not use zero insets for HTML text, which is done in BasicButtonUI.layout() since Java 19.protected void
paintBackground(java.awt.Graphics g, javax.swing.JComponent c)
protected void
paintIcon(java.awt.Graphics g, javax.swing.JComponent c, java.awt.Rectangle iconRect)
protected void
paintText(java.awt.Graphics g, javax.swing.AbstractButton b, java.awt.Rectangle textRect, java.lang.String text)
static void
paintText(java.awt.Graphics g, javax.swing.AbstractButton b, java.awt.Rectangle textRect, java.lang.String text, java.awt.Color foreground)
protected void
propertyChange(javax.swing.AbstractButton b, java.beans.PropertyChangeEvent e)
protected void
uninstallDefaults(javax.swing.AbstractButton b)
void
update(java.awt.Graphics g, javax.swing.JComponent c)
-
Methods inherited from class javax.swing.plaf.basic.BasicButtonUI
clearTextShiftOffset, getBaselineResizeBehavior, getDefaultTextIconGap, getMaximumSize, getMinimumSize, getPropertyPrefix, getTextShiftOffset, installKeyboardActions, installListeners, paintButtonPressed, paintFocus, paintText, setTextShiftOffset, uninstallKeyboardActions, uninstallListeners, uninstallUI
-
-
-
-
Field Detail
-
minimumWidth
protected int minimumWidth
-
iconTextGap
protected int iconTextGap
-
background
protected java.awt.Color background
-
foreground
protected java.awt.Color foreground
-
startBackground
protected java.awt.Color startBackground
-
endBackground
protected java.awt.Color endBackground
-
focusedBackground
protected java.awt.Color focusedBackground
-
focusedForeground
protected java.awt.Color focusedForeground
- Since:
- 2.3
-
hoverBackground
protected java.awt.Color hoverBackground
-
hoverForeground
protected java.awt.Color hoverForeground
- Since:
- 2.3
-
pressedBackground
protected java.awt.Color pressedBackground
-
pressedForeground
protected java.awt.Color pressedForeground
- Since:
- 2.3
-
selectedBackground
protected java.awt.Color selectedBackground
-
selectedForeground
protected java.awt.Color selectedForeground
-
disabledBackground
protected java.awt.Color disabledBackground
-
disabledText
protected java.awt.Color disabledText
-
disabledSelectedBackground
protected java.awt.Color disabledSelectedBackground
-
disabledSelectedForeground
protected java.awt.Color disabledSelectedForeground
- Since:
- 2.3
-
defaultBackground
protected java.awt.Color defaultBackground
-
defaultEndBackground
protected java.awt.Color defaultEndBackground
-
defaultForeground
protected java.awt.Color defaultForeground
-
defaultFocusedBackground
protected java.awt.Color defaultFocusedBackground
-
defaultFocusedForeground
protected java.awt.Color defaultFocusedForeground
- Since:
- 2.3
-
defaultHoverBackground
protected java.awt.Color defaultHoverBackground
-
defaultHoverForeground
protected java.awt.Color defaultHoverForeground
- Since:
- 2.3
-
defaultPressedBackground
protected java.awt.Color defaultPressedBackground
-
defaultPressedForeground
protected java.awt.Color defaultPressedForeground
- Since:
- 2.3
-
defaultBoldText
protected boolean defaultBoldText
-
paintShadow
protected boolean paintShadow
-
shadowWidth
protected int shadowWidth
-
shadowColor
protected java.awt.Color shadowColor
-
defaultShadowColor
protected java.awt.Color defaultShadowColor
-
toolbarHoverBackground
protected java.awt.Color toolbarHoverBackground
-
toolbarHoverForeground
protected java.awt.Color toolbarHoverForeground
- Since:
- 2.3
-
toolbarPressedBackground
protected java.awt.Color toolbarPressedBackground
-
toolbarPressedForeground
protected java.awt.Color toolbarPressedForeground
- Since:
- 2.3
-
toolbarSelectedBackground
protected java.awt.Color toolbarSelectedBackground
-
toolbarSelectedForeground
protected java.awt.Color toolbarSelectedForeground
- Since:
- 2.3
-
toolbarDisabledSelectedBackground
protected java.awt.Color toolbarDisabledSelectedBackground
- Since:
- 2.3
-
toolbarDisabledSelectedForeground
protected java.awt.Color toolbarDisabledSelectedForeground
- Since:
- 2.3
-
buttonType
protected java.lang.String buttonType
- Since:
- 2
-
squareSize
protected boolean squareSize
- Since:
- 2
-
minimumHeight
protected int minimumHeight
- Since:
- 2
-
helpButtonIcon
private javax.swing.Icon helpButtonIcon
-
defaultMargin
private java.awt.Insets defaultMargin
-
shared
private final boolean shared
-
helpButtonIconShared
private boolean helpButtonIconShared
-
defaults_initialized
private boolean defaults_initialized
-
oldStyleValues
private java.util.Map<java.lang.String,java.lang.Object> oldStyleValues
-
borderShared
private java.util.concurrent.atomic.AtomicBoolean borderShared
-
TYPE_OTHER
static final int TYPE_OTHER
- See Also:
- Constant Field Values
-
TYPE_SQUARE
static final int TYPE_SQUARE
- See Also:
- Constant Field Values
-
TYPE_ROUND_RECT
static final int TYPE_ROUND_RECT
- See Also:
- Constant Field Values
-
viewR
private static java.awt.Rectangle viewR
-
textR
private static java.awt.Rectangle textR
-
iconR
private static java.awt.Rectangle iconR
-
-
Method Detail
-
createUI
public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent c)
-
installUI
public void installUI(javax.swing.JComponent c)
- Overrides:
installUI
in classjavax.swing.plaf.basic.BasicButtonUI
-
installUIImpl
private void installUIImpl(javax.swing.JComponent c)
-
installDefaults
protected void installDefaults(javax.swing.AbstractButton b)
- Overrides:
installDefaults
in classjavax.swing.plaf.basic.BasicButtonUI
-
uninstallDefaults
protected void uninstallDefaults(javax.swing.AbstractButton b)
- Overrides:
uninstallDefaults
in classjavax.swing.plaf.basic.BasicButtonUI
-
createButtonListener
protected javax.swing.plaf.basic.BasicButtonListener createButtonListener(javax.swing.AbstractButton b)
- Overrides:
createButtonListener
in classjavax.swing.plaf.basic.BasicButtonUI
-
propertyChange
protected void propertyChange(javax.swing.AbstractButton b, java.beans.PropertyChangeEvent e)
-
installStyle
protected void installStyle(javax.swing.AbstractButton b)
- Since:
- 2
-
getStyleType
java.lang.String getStyleType()
- Since:
- 2
-
applyStyle
protected void applyStyle(javax.swing.AbstractButton b, java.lang.Object style)
- Since:
- 2
-
applyStyleProperty
protected java.lang.Object applyStyleProperty(javax.swing.AbstractButton b, java.lang.String key, java.lang.Object value)
- Since:
- 2
-
getStyleableInfos
public java.util.Map<java.lang.String,java.lang.Class<?>> getStyleableInfos(javax.swing.JComponent c)
- Specified by:
getStyleableInfos
in interfaceFlatStylingSupport.StyleableUI
- Since:
- 2
-
getStyleableValue
public java.lang.Object getStyleableValue(javax.swing.JComponent c, java.lang.String key)
- Specified by:
getStyleableValue
in interfaceFlatStylingSupport.StyleableUI
- Since:
- 2.5
-
isContentAreaFilled
static boolean isContentAreaFilled(java.awt.Component c)
-
isFocusPainted
public static boolean isFocusPainted(java.awt.Component c)
-
isDefaultButton
static boolean isDefaultButton(java.awt.Component c)
-
isIconOnlyOrSingleCharacterButton
static boolean isIconOnlyOrSingleCharacterButton(java.awt.Component c)
Returns true if the button has an icon but no text, or it does not have an icon and the text is either "..." or one character.
-
getButtonType
static int getButtonType(java.awt.Component c)
-
isHelpButton
static boolean isHelpButton(java.awt.Component c)
-
isToolBarButton
static boolean isToolBarButton(java.awt.Component c)
-
isBorderlessButton
static boolean isBorderlessButton(java.awt.Component c)
-
getButtonTypeStr
static java.lang.String getButtonTypeStr(javax.swing.AbstractButton c)
-
update
public void update(java.awt.Graphics g, javax.swing.JComponent c)
- Overrides:
update
in classjavax.swing.plaf.ComponentUI
-
paintBackground
protected void paintBackground(java.awt.Graphics g, javax.swing.JComponent c)
-
paint
public void paint(java.awt.Graphics g, javax.swing.JComponent c)
Similar to BasicButtonUI.paint(), but does not use zero insets for HTML text, which is done in BasicButtonUI.layout() since Java 19. See https://github.com/openjdk/jdk/pull/8407 and https://github.com/openjdk/jdk/pull/8407#issuecomment-1761583430- Overrides:
paint
in classjavax.swing.plaf.basic.BasicButtonUI
-
paintIcon
protected void paintIcon(java.awt.Graphics g, javax.swing.JComponent c, java.awt.Rectangle iconRect)
- Overrides:
paintIcon
in classjavax.swing.plaf.basic.BasicButtonUI
-
paintText
protected void paintText(java.awt.Graphics g, javax.swing.AbstractButton b, java.awt.Rectangle textRect, java.lang.String text)
- Overrides:
paintText
in classjavax.swing.plaf.basic.BasicButtonUI
-
paintText
public static void paintText(java.awt.Graphics g, javax.swing.AbstractButton b, java.awt.Rectangle textRect, java.lang.String text, java.awt.Color foreground)
-
getBackground
protected java.awt.Color getBackground(javax.swing.JComponent c)
-
getBackgroundBase
protected java.awt.Color getBackgroundBase(javax.swing.JComponent c, boolean def)
-
isCustomBackground
protected boolean isCustomBackground(java.awt.Color bg)
-
buttonStateColor
public static java.awt.Color buttonStateColor(java.awt.Component c, java.awt.Color enabledColor, java.awt.Color disabledColor, java.awt.Color focusedColor, java.awt.Color hoverColor, java.awt.Color pressedColor)
-
getForeground
protected java.awt.Color getForeground(javax.swing.JComponent c)
-
getForegroundBase
protected java.awt.Color getForegroundBase(javax.swing.JComponent c, boolean def)
- Since:
- 2.3
-
isCustomForeground
protected boolean isCustomForeground(java.awt.Color fg)
-
getPreferredSize
public java.awt.Dimension getPreferredSize(javax.swing.JComponent c)
- Overrides:
getPreferredSize
in classjavax.swing.plaf.basic.BasicButtonUI
-
defaultBoldPlainWidthDiff
private int defaultBoldPlainWidthDiff(javax.swing.JComponent c)
-
hasDefaultMargins
private boolean hasDefaultMargins(javax.swing.JComponent c)
-
getBaseline
public int getBaseline(javax.swing.JComponent c, int width, int height)
- Overrides:
getBaseline
in classjavax.swing.plaf.basic.BasicButtonUI
-
getBaselineImpl
static int getBaselineImpl(javax.swing.JComponent c, int width, int height)
Similar to BasicButtonUI.getBaseline(), but does not use zero insets for HTML text, which is done in BasicButtonUI.layout() since Java 19. See https://github.com/openjdk/jdk/pull/8407 and https://github.com/openjdk/jdk/pull/8407#issuecomment-1761583430
-
layout
private static java.lang.String layout(javax.swing.AbstractButton b, java.awt.FontMetrics fm, int width, int height)
Similar to BasicButtonUI.layout(), but does not use zero insets for HTML text, which is done in BasicButtonUI.layout() since Java 19. See https://github.com/openjdk/jdk/pull/8407 and https://github.com/openjdk/jdk/pull/8407#issuecomment-1761583430
-
-