mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-09 08:15:09 +03:00
Button: support non-square icon-only buttons (issue #110)
This commit is contained in:
@@ -8,6 +8,7 @@ FlatLaf Change Log
|
||||
- ComboBox: Minimum width is now 72 pixels (was ~50 for non-editable and ~130
|
||||
for editable comboboxes).
|
||||
- ComboBox: Support custom borders in combobox editors. (issue #102)
|
||||
- Button: Support non-square icon-only buttons. (issue #110)
|
||||
- Ubuntu Linux: Fixed poorly rendered font. (issue #105)
|
||||
- macOS Catalina: Use Helvetica Neue font.
|
||||
|
||||
|
||||
@@ -114,8 +114,8 @@ public class FlatButtonBorder
|
||||
} else {
|
||||
insets = super.getBorderInsets( c, insets );
|
||||
|
||||
// use smaller left and right insets for icon-only buttons (so that they are square)
|
||||
if( FlatButtonUI.isIconOnlyButton( c ) && ((AbstractButton)c).getMargin() instanceof UIResource )
|
||||
// use smaller left and right insets for icon-only or single-character buttons (so that they are square)
|
||||
if( FlatButtonUI.isIconOnlyOrSingleCharacterButton( c ) && ((AbstractButton)c).getMargin() instanceof UIResource )
|
||||
insets.left = insets.right = Math.min( insets.top, insets.bottom );
|
||||
}
|
||||
|
||||
|
||||
@@ -224,7 +224,11 @@ public class FlatButtonUI
|
||||
return c instanceof JButton && ((JButton)c).isDefaultButton();
|
||||
}
|
||||
|
||||
static boolean isIconOnlyButton( Component c ) {
|
||||
/**
|
||||
* Returns true if the button has an icon but no text,
|
||||
* or it it does not have an icon and the text is either "..." or one character.
|
||||
*/
|
||||
static boolean isIconOnlyOrSingleCharacterButton( Component c ) {
|
||||
if( !(c instanceof JButton) && !(c instanceof JToggleButton) )
|
||||
return false;
|
||||
|
||||
@@ -409,11 +413,13 @@ public class FlatButtonUI
|
||||
if( prefSize == null )
|
||||
return null;
|
||||
|
||||
// make button square if it is a icon-only button
|
||||
// or apply minimum width, if not in toolbar and not a icon-only button
|
||||
if( isIconOnlyButton( c ) )
|
||||
// make button square if it is a single-character button
|
||||
// or apply minimum width, if not in toolbar and not a icon-only or single-character button
|
||||
if( isIconOnlyOrSingleCharacterButton( c ) ) {
|
||||
// make only single-character buttons square to allow non-square icon-only buttons
|
||||
if( ((AbstractButton)c).getIcon() == null )
|
||||
prefSize.width = Math.max( prefSize.width, prefSize.height );
|
||||
else if( !isToolBarButton( c ) && c.getBorder() instanceof FlatButtonBorder ) {
|
||||
} else if( !isToolBarButton( c ) && c.getBorder() instanceof FlatButtonBorder ) {
|
||||
float focusWidth = FlatUIUtils.getBorderFocusWidth( c );
|
||||
prefSize.width = Math.max( prefSize.width, scale( FlatUIUtils.minimumWidth( c, minimumWidth ) ) + Math.round( focusWidth * 2 ) );
|
||||
prefSize.height = Math.max( prefSize.height, scale( FlatUIUtils.minimumHeight( c, 0 ) ) + Math.round( focusWidth * 2 ) );
|
||||
|
||||
Reference in New Issue
Block a user