mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 07:17: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`).
|
`JButton.buttonType` to `square`).
|
||||||
- ToggleButton: Support underline toggle button style (set client property
|
- ToggleButton: Support underline toggle button style (set client property
|
||||||
`JButton.buttonType` to `underline`).
|
`JButton.buttonType` to `underline`).
|
||||||
|
- Button and TextComponent: Support per component minimum width (set client
|
||||||
|
property `JComponent.minimumWidth` to an integer).
|
||||||
|
|
||||||
|
|
||||||
## 0.23.1
|
## 0.23.1
|
||||||
|
|||||||
@@ -76,6 +76,14 @@ public interface FlatClientProperties
|
|||||||
*/
|
*/
|
||||||
String SELECTED_STATE_INDETERMINATE = "indeterminate";
|
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.
|
* Specifies whether the decrease/increase arrow buttons of a scrollbar are shown.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -363,7 +363,7 @@ public class FlatButtonUI
|
|||||||
if( isIconOnlyButton( c ) )
|
if( isIconOnlyButton( c ) )
|
||||||
prefSize.width = Math.max( prefSize.width, prefSize.height );
|
prefSize.width = Math.max( prefSize.width, prefSize.height );
|
||||||
else if( !isToolBarButton( c ) )
|
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;
|
return prefSize;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ public class FlatEditorPaneUI
|
|||||||
// and subtract 1px border line width.
|
// and subtract 1px border line width.
|
||||||
// Using "(scale( 1 ) * 2)" instead of "scale( 2 )" to deal with rounding
|
// 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.
|
// 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) );
|
size.width = Math.max( size.width, scale( minimumWidth ) - (scale( 1 ) * 2) );
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -147,6 +147,7 @@ public class FlatPasswordFieldUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Dimension applyMinimumWidth( Dimension size, JComponent c ) {
|
private Dimension applyMinimumWidth( Dimension size, JComponent c ) {
|
||||||
|
int minimumWidth = FlatUIUtils.minimumWidth( getComponent(), this.minimumWidth );
|
||||||
int focusWidth = (c.getBorder() instanceof FlatBorder) ? this.focusWidth : 0;
|
int focusWidth = (c.getBorder() instanceof FlatBorder) ? this.focusWidth : 0;
|
||||||
size.width = Math.max( size.width, scale( minimumWidth + (focusWidth * 2) ) );
|
size.width = Math.max( size.width, scale( minimumWidth + (focusWidth * 2) ) );
|
||||||
return size;
|
return size;
|
||||||
|
|||||||
@@ -326,6 +326,7 @@ public class FlatSpinnerUI
|
|||||||
Dimension editorSize = (editor != null) ? editor.getPreferredSize() : new Dimension( 0, 0 );
|
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
|
// 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;
|
int innerHeight = editorSize.height + padding.top + padding.bottom;
|
||||||
return new Dimension(
|
return new Dimension(
|
||||||
Math.max( insets.left + insets.right + editorSize.width + padding.left + padding.right + innerHeight, scale( minimumWidth + (focusWidth * 2) ) ),
|
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.
|
// and subtract 1px border line width.
|
||||||
// Using "(scale( 1 ) * 2)" instead of "scale( 2 )" to deal with rounding
|
// 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.
|
// 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) );
|
size.width = Math.max( size.width, scale( minimumWidth ) - (scale( 1 ) * 2) );
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ public class FlatTextFieldUI
|
|||||||
(parent != null && parent.getParent() instanceof JSpinner) )
|
(parent != null && parent.getParent() instanceof JSpinner) )
|
||||||
return size;
|
return size;
|
||||||
|
|
||||||
|
int minimumWidth = FlatUIUtils.minimumWidth( getComponent(), this.minimumWidth );
|
||||||
int focusWidth = (c.getBorder() instanceof FlatBorder) ? this.focusWidth : 0;
|
int focusWidth = (c.getBorder() instanceof FlatBorder) ? this.focusWidth : 0;
|
||||||
size.width = Math.max( size.width, scale( minimumWidth + (focusWidth * 2) ) );
|
size.width = Math.max( size.width, scale( minimumWidth + (focusWidth * 2) ) );
|
||||||
return size;
|
return size;
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ public class FlatTextPaneUI
|
|||||||
// and subtract 1px border line width.
|
// and subtract 1px border line width.
|
||||||
// Using "(scale( 1 ) * 2)" instead of "scale( 2 )" to deal with rounding
|
// 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.
|
// 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) );
|
size.width = Math.max( size.width, scale( minimumWidth ) - (scale( 1 ) * 2) );
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import javax.swing.JComponent;
|
|||||||
import javax.swing.LookAndFeel;
|
import javax.swing.LookAndFeel;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ColorUIResource;
|
import javax.swing.plaf.ColorUIResource;
|
||||||
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
import com.formdev.flatlaf.util.DerivedColor;
|
import com.formdev.flatlaf.util.DerivedColor;
|
||||||
import com.formdev.flatlaf.util.HiDPIUtils;
|
import com.formdev.flatlaf.util.HiDPIUtils;
|
||||||
import com.formdev.flatlaf.util.JavaCompatibility;
|
import com.formdev.flatlaf.util.JavaCompatibility;
|
||||||
@@ -111,6 +112,11 @@ 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 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 ) {
|
public static boolean isTableCellEditor( Component c ) {
|
||||||
return c instanceof JComponent && Boolean.TRUE.equals( ((JComponent)c).getClientProperty( "JComboBox.isTableCellEditor" ) );
|
return c instanceof JComponent && Boolean.TRUE.equals( ((JComponent)c).getClientProperty( "JComboBox.isTableCellEditor" ) );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -258,6 +258,7 @@ public class FlatComponentsTest
|
|||||||
//---- button17 ----
|
//---- button17 ----
|
||||||
button17.setText("square");
|
button17.setText("square");
|
||||||
button17.putClientProperty("JButton.buttonType", "square");
|
button17.putClientProperty("JButton.buttonType", "square");
|
||||||
|
button17.putClientProperty("JComponent.minimumWidth", 0);
|
||||||
add(button17, "cell 1 1");
|
add(button17, "cell 1 1");
|
||||||
|
|
||||||
//---- button2 ----
|
//---- button2 ----
|
||||||
@@ -271,6 +272,7 @@ public class FlatComponentsTest
|
|||||||
button18.setText("square");
|
button18.setText("square");
|
||||||
button18.putClientProperty("JButton.buttonType", "square");
|
button18.putClientProperty("JButton.buttonType", "square");
|
||||||
button18.setEnabled(false);
|
button18.setEnabled(false);
|
||||||
|
button18.putClientProperty("JComponent.minimumWidth", 0);
|
||||||
add(button18, "cell 2 1");
|
add(button18, "cell 2 1");
|
||||||
|
|
||||||
//---- button5 ----
|
//---- button5 ----
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ new FormModel {
|
|||||||
name: "button17"
|
name: "button17"
|
||||||
"text": "square"
|
"text": "square"
|
||||||
"$client.JButton.buttonType": "square"
|
"$client.JButton.buttonType": "square"
|
||||||
|
"$client.JComponent.minimumWidth": 0
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 1 1"
|
"value": "cell 1 1"
|
||||||
} )
|
} )
|
||||||
@@ -68,6 +69,7 @@ new FormModel {
|
|||||||
"text": "square"
|
"text": "square"
|
||||||
"$client.JButton.buttonType": "square"
|
"$client.JButton.buttonType": "square"
|
||||||
"enabled": false
|
"enabled": false
|
||||||
|
"$client.JComponent.minimumWidth": 0
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 2 1"
|
"value": "cell 2 1"
|
||||||
} )
|
} )
|
||||||
|
|||||||
Reference in New Issue
Block a user