mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 06:57:13 -06:00
Button: apply minimum button width of 72px
This commit is contained in:
@@ -30,6 +30,7 @@ import javax.swing.ButtonModel;
|
|||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JToolBar;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
@@ -42,6 +43,7 @@ import javax.swing.plaf.basic.BasicButtonUI;
|
|||||||
*
|
*
|
||||||
* @uiDefault Component.focusWidth int
|
* @uiDefault Component.focusWidth int
|
||||||
* @uiDefault Button.arc int
|
* @uiDefault Button.arc int
|
||||||
|
* @uiDefault Button.minimumWidth int
|
||||||
* @uiDefault Button.disabledText Color
|
* @uiDefault Button.disabledText Color
|
||||||
* @uiDefault Button.default.background Color
|
* @uiDefault Button.default.background Color
|
||||||
* @uiDefault Button.default.foreground Color
|
* @uiDefault Button.default.foreground Color
|
||||||
@@ -55,6 +57,7 @@ public class FlatButtonUI
|
|||||||
{
|
{
|
||||||
protected int focusWidth;
|
protected int focusWidth;
|
||||||
protected int arc;
|
protected int arc;
|
||||||
|
protected int minimumWidth;
|
||||||
|
|
||||||
protected Color disabledText;
|
protected Color disabledText;
|
||||||
protected Color defaultBackground;
|
protected Color defaultBackground;
|
||||||
@@ -80,6 +83,7 @@ public class FlatButtonUI
|
|||||||
|
|
||||||
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||||
arc = UIManager.getInt( prefix + "arc" );
|
arc = UIManager.getInt( prefix + "arc" );
|
||||||
|
minimumWidth = UIManager.getInt( prefix + "minimumWidth" );
|
||||||
|
|
||||||
disabledText = UIManager.getColor( prefix + "disabledText" );
|
disabledText = UIManager.getColor( prefix + "disabledText" );
|
||||||
defaultBackground = UIManager.getColor( prefix + "default.background" );
|
defaultBackground = UIManager.getColor( prefix + "default.background" );
|
||||||
@@ -102,6 +106,10 @@ public class FlatButtonUI
|
|||||||
return c instanceof JButton && clientPropertyEquals( (JButton) c, BUTTON_TYPE, BUTTON_TYPE_HELP );
|
return c instanceof JButton && clientPropertyEquals( (JButton) c, BUTTON_TYPE, BUTTON_TYPE_HELP );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean isToolBarButton( JComponent c ) {
|
||||||
|
return c.getParent() instanceof JToolBar;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update( Graphics g, JComponent c ) {
|
public void update( Graphics g, JComponent c ) {
|
||||||
if( isHelpButton( c ) ) {
|
if( isHelpButton( c ) ) {
|
||||||
@@ -121,7 +129,7 @@ public class FlatButtonUI
|
|||||||
|
|
||||||
Border border = c.getBorder();
|
Border border = c.getBorder();
|
||||||
float focusWidth = (border instanceof FlatBorder) ? scale( (float) this.focusWidth ) : 0;
|
float focusWidth = (border instanceof FlatBorder) ? scale( (float) this.focusWidth ) : 0;
|
||||||
float arc = (border instanceof FlatButtonBorder || FlatUIUtils.isToolBarButton( c )) ? scale( (float) this.arc ) : 0;
|
float arc = (border instanceof FlatButtonBorder || isToolBarButton( c )) ? scale( (float) this.arc ) : 0;
|
||||||
|
|
||||||
g2.setColor( background );
|
g2.setColor( background );
|
||||||
FlatUIUtils.fillRoundRectangle( g2, 0, 0, c.getWidth(), c.getHeight(), focusWidth, arc );
|
FlatUIUtils.fillRoundRectangle( g2, 0, 0, c.getWidth(), c.getHeight(), focusWidth, arc );
|
||||||
@@ -156,7 +164,7 @@ public class FlatButtonUI
|
|||||||
ButtonModel model = ((AbstractButton)c).getModel();
|
ButtonModel model = ((AbstractButton)c).getModel();
|
||||||
|
|
||||||
// toolbar button
|
// toolbar button
|
||||||
if( FlatUIUtils.isToolBarButton( c ) ) {
|
if( isToolBarButton( c ) ) {
|
||||||
if( model.isPressed() )
|
if( model.isPressed() )
|
||||||
return toolbarPressedBackground;
|
return toolbarPressedBackground;
|
||||||
if( model.isRollover() )
|
if( model.isRollover() )
|
||||||
@@ -180,6 +188,9 @@ public class FlatButtonUI
|
|||||||
if( isHelpButton( c ) )
|
if( isHelpButton( c ) )
|
||||||
return new Dimension( helpButtonIcon.getIconWidth(), helpButtonIcon.getIconHeight() );
|
return new Dimension( helpButtonIcon.getIconWidth(), helpButtonIcon.getIconHeight() );
|
||||||
|
|
||||||
return super.getPreferredSize( c );
|
Dimension prefSize = super.getPreferredSize( c );
|
||||||
|
if( !isToolBarButton( c ) )
|
||||||
|
prefSize.width = Math.max( prefSize.width, scale( minimumWidth + (focusWidth * 2) ) );
|
||||||
|
return prefSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public class FlatToggleButtonUI
|
|||||||
ButtonModel model = ((AbstractButton)c).getModel();
|
ButtonModel model = ((AbstractButton)c).getModel();
|
||||||
|
|
||||||
if( model.isSelected() ) {
|
if( model.isSelected() ) {
|
||||||
return FlatUIUtils.isToolBarButton( c )
|
return isToolBarButton( c )
|
||||||
? toolbarPressedBackground
|
? toolbarPressedBackground
|
||||||
: (c.isEnabled() ? selectedBackground : disabledSelectedBackground);
|
: (c.isEnabled() ? selectedBackground : disabledSelectedBackground);
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ public class FlatToggleButtonUI
|
|||||||
protected Color getForeground( JComponent c ) {
|
protected Color getForeground( JComponent c ) {
|
||||||
ButtonModel model = ((AbstractButton)c).getModel();
|
ButtonModel model = ((AbstractButton)c).getModel();
|
||||||
|
|
||||||
if( model.isSelected() && !FlatUIUtils.isToolBarButton( c ) )
|
if( model.isSelected() && !isToolBarButton( c ) )
|
||||||
return selectedForeground;
|
return selectedForeground;
|
||||||
|
|
||||||
return super.getForeground( c );
|
return super.getForeground( c );
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import java.awt.RenderingHints;
|
|||||||
import java.awt.geom.Path2D;
|
import java.awt.geom.Path2D;
|
||||||
import java.awt.geom.RoundRectangle2D;
|
import java.awt.geom.RoundRectangle2D;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JToolBar;
|
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ColorUIResource;
|
import javax.swing.plaf.ColorUIResource;
|
||||||
import com.formdev.flatlaf.util.JavaCompatibility;
|
import com.formdev.flatlaf.util.JavaCompatibility;
|
||||||
@@ -63,10 +62,6 @@ public class FlatUIUtils
|
|||||||
return (c instanceof ColorUIResource) ? new Color( c.getRGB(), true ) : c;
|
return (c instanceof ColorUIResource) ? new Color( c.getRGB(), true ) : c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isToolBarButton( JComponent c ) {
|
|
||||||
return c.getParent() instanceof JToolBar;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets rendering hints used for painting.
|
* Sets rendering hints used for painting.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ ViewportUI=com.formdev.flatlaf.ui.FlatViewportUI
|
|||||||
|
|
||||||
Button.border=com.formdev.flatlaf.ui.FlatButtonBorder
|
Button.border=com.formdev.flatlaf.ui.FlatButtonBorder
|
||||||
Button.arc=6
|
Button.arc=6
|
||||||
|
Button.minimumWidth=72
|
||||||
|
|
||||||
|
|
||||||
#---- CheckBox ----
|
#---- CheckBox ----
|
||||||
@@ -189,7 +190,7 @@ OptionPane.maxCharactersPerLine=80
|
|||||||
OptionPane.iconMessageGap=16
|
OptionPane.iconMessageGap=16
|
||||||
OptionPane.messagePadding=3
|
OptionPane.messagePadding=3
|
||||||
OptionPane.buttonPadding=8
|
OptionPane.buttonPadding=8
|
||||||
OptionPane.buttonMinimumWidth=80
|
OptionPane.buttonMinimumWidth=72
|
||||||
OptionPane.sameSizeButtons=true
|
OptionPane.sameSizeButtons=true
|
||||||
OptionPane.setButtonMargin=false
|
OptionPane.setButtonMargin=false
|
||||||
OptionPane.buttonOrientation=4
|
OptionPane.buttonOrientation=4
|
||||||
|
|||||||
Reference in New Issue
Block a user