mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
Button and TextComponent: support per component minimum width
This commit is contained in:
@@ -13,6 +13,8 @@ FlatLaf Change Log
|
||||
`JButton.buttonType` to `square`).
|
||||
- ToggleButton: Support underline toggle button style (set client property
|
||||
`JButton.buttonType` to `underline`).
|
||||
- Button and TextComponent: Support per component minimum width (set client
|
||||
property `JComponent.minimumWidth` to an integer).
|
||||
|
||||
|
||||
## 0.23.1
|
||||
|
||||
@@ -76,6 +76,14 @@ public interface FlatClientProperties
|
||||
*/
|
||||
String SELECTED_STATE_INDETERMINATE = "indeterminate";
|
||||
|
||||
/**
|
||||
* Specifies minimum width of a component.
|
||||
* <p>
|
||||
* <strong>Component</strong> {@link javax.swing.JButton} and {@link javax.swing.text.JTextComponent}<br>
|
||||
* <strong>Value type</strong> {@link java.lang.Integer}<br>
|
||||
*/
|
||||
String MINIMUM_WIDTH = "JComponent.minimumWidth";
|
||||
|
||||
/**
|
||||
* Specifies whether the decrease/increase arrow buttons of a scrollbar are shown.
|
||||
* <p>
|
||||
|
||||
@@ -363,7 +363,7 @@ public class FlatButtonUI
|
||||
if( isIconOnlyButton( c ) )
|
||||
prefSize.width = Math.max( prefSize.width, prefSize.height );
|
||||
else if( !isToolBarButton( c ) )
|
||||
prefSize.width = Math.max( prefSize.width, scale( minimumWidth + (focusWidth * 2) ) );
|
||||
prefSize.width = Math.max( prefSize.width, scale( FlatUIUtils.minimumWidth( c, minimumWidth ) + (focusWidth * 2) ) );
|
||||
|
||||
return prefSize;
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@ public class FlatEditorPaneUI
|
||||
// and subtract 1px border line width.
|
||||
// Using "(scale( 1 ) * 2)" instead of "scale( 2 )" to deal with rounding
|
||||
// issues. E.g. at scale factor 1.5 the first returns 4, but the second 3.
|
||||
int minimumWidth = FlatUIUtils.minimumWidth( getComponent(), this.minimumWidth );
|
||||
size.width = Math.max( size.width, scale( minimumWidth ) - (scale( 1 ) * 2) );
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -147,6 +147,7 @@ public class FlatPasswordFieldUI
|
||||
}
|
||||
|
||||
private Dimension applyMinimumWidth( Dimension size, JComponent c ) {
|
||||
int minimumWidth = FlatUIUtils.minimumWidth( getComponent(), this.minimumWidth );
|
||||
int focusWidth = (c.getBorder() instanceof FlatBorder) ? this.focusWidth : 0;
|
||||
size.width = Math.max( size.width, scale( minimumWidth + (focusWidth * 2) ) );
|
||||
return size;
|
||||
|
||||
@@ -326,6 +326,7 @@ public class FlatSpinnerUI
|
||||
Dimension editorSize = (editor != null) ? editor.getPreferredSize() : new Dimension( 0, 0 );
|
||||
|
||||
// the arrows width is the same as the inner height so that the arrows area is square
|
||||
int minimumWidth = FlatUIUtils.minimumWidth( spinner, FlatSpinnerUI.this.minimumWidth );
|
||||
int innerHeight = editorSize.height + padding.top + padding.bottom;
|
||||
return new Dimension(
|
||||
Math.max( insets.left + insets.right + editorSize.width + padding.left + padding.right + innerHeight, scale( minimumWidth + (focusWidth * 2) ) ),
|
||||
|
||||
@@ -117,6 +117,7 @@ public class FlatTextAreaUI
|
||||
// and subtract 1px border line width.
|
||||
// Using "(scale( 1 ) * 2)" instead of "scale( 2 )" to deal with rounding
|
||||
// issues. E.g. at scale factor 1.5 the first returns 4, but the second 3.
|
||||
int minimumWidth = FlatUIUtils.minimumWidth( getComponent(), this.minimumWidth );
|
||||
size.width = Math.max( size.width, scale( minimumWidth ) - (scale( 1 ) * 2) );
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -217,6 +217,7 @@ public class FlatTextFieldUI
|
||||
(parent != null && parent.getParent() instanceof JSpinner) )
|
||||
return size;
|
||||
|
||||
int minimumWidth = FlatUIUtils.minimumWidth( getComponent(), this.minimumWidth );
|
||||
int focusWidth = (c.getBorder() instanceof FlatBorder) ? this.focusWidth : 0;
|
||||
size.width = Math.max( size.width, scale( minimumWidth + (focusWidth * 2) ) );
|
||||
return size;
|
||||
|
||||
@@ -98,6 +98,7 @@ public class FlatTextPaneUI
|
||||
// and subtract 1px border line width.
|
||||
// Using "(scale( 1 ) * 2)" instead of "scale( 2 )" to deal with rounding
|
||||
// issues. E.g. at scale factor 1.5 the first returns 4, but the second 3.
|
||||
int minimumWidth = FlatUIUtils.minimumWidth( getComponent(), this.minimumWidth );
|
||||
size.width = Math.max( size.width, scale( minimumWidth ) - (scale( 1 ) * 2) );
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import javax.swing.JComponent;
|
||||
import javax.swing.LookAndFeel;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.ColorUIResource;
|
||||
import com.formdev.flatlaf.FlatClientProperties;
|
||||
import com.formdev.flatlaf.util.DerivedColor;
|
||||
import com.formdev.flatlaf.util.HiDPIUtils;
|
||||
import com.formdev.flatlaf.util.JavaCompatibility;
|
||||
@@ -111,6 +112,11 @@ public class FlatUIUtils
|
||||
return (c instanceof ColorUIResource) ? new Color( c.getRGB(), true ) : c;
|
||||
}
|
||||
|
||||
public static int minimumWidth( JComponent c, int minimumWidth ) {
|
||||
Object p = c.getClientProperty( FlatClientProperties.MINIMUM_WIDTH );
|
||||
return (p instanceof Integer) ? ((Integer)p).intValue() : minimumWidth;
|
||||
}
|
||||
|
||||
public static boolean isTableCellEditor( Component c ) {
|
||||
return c instanceof JComponent && Boolean.TRUE.equals( ((JComponent)c).getClientProperty( "JComboBox.isTableCellEditor" ) );
|
||||
}
|
||||
|
||||
@@ -258,6 +258,7 @@ public class FlatComponentsTest
|
||||
//---- button17 ----
|
||||
button17.setText("square");
|
||||
button17.putClientProperty("JButton.buttonType", "square");
|
||||
button17.putClientProperty("JComponent.minimumWidth", 0);
|
||||
add(button17, "cell 1 1");
|
||||
|
||||
//---- button2 ----
|
||||
@@ -271,6 +272,7 @@ public class FlatComponentsTest
|
||||
button18.setText("square");
|
||||
button18.putClientProperty("JButton.buttonType", "square");
|
||||
button18.setEnabled(false);
|
||||
button18.putClientProperty("JComponent.minimumWidth", 0);
|
||||
add(button18, "cell 2 1");
|
||||
|
||||
//---- button5 ----
|
||||
|
||||
@@ -51,6 +51,7 @@ new FormModel {
|
||||
name: "button17"
|
||||
"text": "square"
|
||||
"$client.JButton.buttonType": "square"
|
||||
"$client.JComponent.minimumWidth": 0
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 1"
|
||||
} )
|
||||
@@ -68,6 +69,7 @@ new FormModel {
|
||||
"text": "square"
|
||||
"$client.JButton.buttonType": "square"
|
||||
"enabled": false
|
||||
"$client.JComponent.minimumWidth": 0
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 1"
|
||||
} )
|
||||
|
||||
Reference in New Issue
Block a user