mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27: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.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JToolBar;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
@@ -42,6 +43,7 @@ import javax.swing.plaf.basic.BasicButtonUI;
|
||||
*
|
||||
* @uiDefault Component.focusWidth int
|
||||
* @uiDefault Button.arc int
|
||||
* @uiDefault Button.minimumWidth int
|
||||
* @uiDefault Button.disabledText Color
|
||||
* @uiDefault Button.default.background Color
|
||||
* @uiDefault Button.default.foreground Color
|
||||
@@ -55,6 +57,7 @@ public class FlatButtonUI
|
||||
{
|
||||
protected int focusWidth;
|
||||
protected int arc;
|
||||
protected int minimumWidth;
|
||||
|
||||
protected Color disabledText;
|
||||
protected Color defaultBackground;
|
||||
@@ -80,6 +83,7 @@ public class FlatButtonUI
|
||||
|
||||
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||
arc = UIManager.getInt( prefix + "arc" );
|
||||
minimumWidth = UIManager.getInt( prefix + "minimumWidth" );
|
||||
|
||||
disabledText = UIManager.getColor( prefix + "disabledText" );
|
||||
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 );
|
||||
}
|
||||
|
||||
static boolean isToolBarButton( JComponent c ) {
|
||||
return c.getParent() instanceof JToolBar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( Graphics g, JComponent c ) {
|
||||
if( isHelpButton( c ) ) {
|
||||
@@ -121,7 +129,7 @@ public class FlatButtonUI
|
||||
|
||||
Border border = c.getBorder();
|
||||
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 );
|
||||
FlatUIUtils.fillRoundRectangle( g2, 0, 0, c.getWidth(), c.getHeight(), focusWidth, arc );
|
||||
@@ -156,7 +164,7 @@ public class FlatButtonUI
|
||||
ButtonModel model = ((AbstractButton)c).getModel();
|
||||
|
||||
// toolbar button
|
||||
if( FlatUIUtils.isToolBarButton( c ) ) {
|
||||
if( isToolBarButton( c ) ) {
|
||||
if( model.isPressed() )
|
||||
return toolbarPressedBackground;
|
||||
if( model.isRollover() )
|
||||
@@ -180,6 +188,9 @@ public class FlatButtonUI
|
||||
if( isHelpButton( c ) )
|
||||
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();
|
||||
|
||||
if( model.isSelected() ) {
|
||||
return FlatUIUtils.isToolBarButton( c )
|
||||
return isToolBarButton( c )
|
||||
? toolbarPressedBackground
|
||||
: (c.isEnabled() ? selectedBackground : disabledSelectedBackground);
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public class FlatToggleButtonUI
|
||||
protected Color getForeground( JComponent c ) {
|
||||
ButtonModel model = ((AbstractButton)c).getModel();
|
||||
|
||||
if( model.isSelected() && !FlatUIUtils.isToolBarButton( c ) )
|
||||
if( model.isSelected() && !isToolBarButton( c ) )
|
||||
return selectedForeground;
|
||||
|
||||
return super.getForeground( c );
|
||||
|
||||
@@ -26,7 +26,6 @@ import java.awt.RenderingHints;
|
||||
import java.awt.geom.Path2D;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JToolBar;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.ColorUIResource;
|
||||
import com.formdev.flatlaf.util.JavaCompatibility;
|
||||
@@ -63,10 +62,6 @@ public class FlatUIUtils
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -64,6 +64,7 @@ ViewportUI=com.formdev.flatlaf.ui.FlatViewportUI
|
||||
|
||||
Button.border=com.formdev.flatlaf.ui.FlatButtonBorder
|
||||
Button.arc=6
|
||||
Button.minimumWidth=72
|
||||
|
||||
|
||||
#---- CheckBox ----
|
||||
@@ -189,7 +190,7 @@ OptionPane.maxCharactersPerLine=80
|
||||
OptionPane.iconMessageGap=16
|
||||
OptionPane.messagePadding=3
|
||||
OptionPane.buttonPadding=8
|
||||
OptionPane.buttonMinimumWidth=80
|
||||
OptionPane.buttonMinimumWidth=72
|
||||
OptionPane.sameSizeButtons=true
|
||||
OptionPane.setButtonMargin=false
|
||||
OptionPane.buttonOrientation=4
|
||||
|
||||
Reference in New Issue
Block a user