mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 06:57:13 -06:00
fixed component heights at 1.25x, 1.75x and 2.25x scaling factors (Java 8 only) so that Button, ComboBox, Spinner and TextField components (including subclasses) have same heights
This commit is contained in:
@@ -23,8 +23,8 @@ plugins {
|
||||
|
||||
dependencies {
|
||||
testImplementation( "org.junit.jupiter:junit-jupiter-api:5.7.2" )
|
||||
testImplementation( "org.junit.jupiter:junit-jupiter-params" )
|
||||
testRuntimeOnly( "org.junit.jupiter:junit-jupiter-engine" )
|
||||
testRuntimeOnly( "org.junit.jupiter:junit-jupiter-params" )
|
||||
}
|
||||
|
||||
java {
|
||||
|
||||
@@ -176,13 +176,14 @@ public class FlatBorder
|
||||
@Override
|
||||
public Insets getBorderInsets( Component c, Insets insets ) {
|
||||
float focusWidth = scale( (float) getFocusWidth( c ) );
|
||||
float ow = focusWidth + scale( (float) getLineWidth( c ) );
|
||||
int ow = Math.round( focusWidth + scale( (float) getLineWidth( c ) ) );
|
||||
|
||||
insets = super.getBorderInsets( c, insets );
|
||||
insets.top = Math.round( scale( (float) insets.top ) + ow );
|
||||
insets.left = Math.round( scale( (float) insets.left ) + ow );
|
||||
insets.bottom = Math.round( scale( (float) insets.bottom ) + ow );
|
||||
insets.right = Math.round( scale( (float) insets.right ) + ow );
|
||||
|
||||
insets.top = scale( insets.top ) + ow;
|
||||
insets.left = scale( insets.left ) + ow;
|
||||
insets.bottom = scale( insets.bottom ) + ow;
|
||||
insets.right = scale( insets.right ) + ow;
|
||||
|
||||
if( isCellEditor( c ) ) {
|
||||
// remove top and bottom insets if used as cell editor
|
||||
|
||||
@@ -49,7 +49,7 @@ public class TestFlatComponentSizes
|
||||
}
|
||||
|
||||
static float[] factors() {
|
||||
return new float[] { 1f, 1.25f, 1.5f, 1.75f, 2f, 2.25f, 2.5f, 3f, 4f };
|
||||
return TestUtils.FACTORS;
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -57,12 +57,6 @@ public class TestFlatComponentSizes
|
||||
void sizes( float factor ) {
|
||||
TestUtils.scaleFont( factor );
|
||||
|
||||
// TODO on some scale factors the combobox/spinner sizes are slightly different
|
||||
// because different size calculation methods and rounding
|
||||
boolean testComboBoxAndSpinner = (UIManager.getInt( "Component.focusWidth" ) > 0)
|
||||
? (factor != 1.25 && factor != 2.25)
|
||||
: (factor != 1.75);
|
||||
|
||||
|
||||
// should have same default size (minimumWidth is 64)
|
||||
JTextField textField = new JTextField();
|
||||
@@ -73,8 +67,7 @@ public class TestFlatComponentSizes
|
||||
Dimension textFieldSize = textField.getPreferredSize();
|
||||
assertEquals( textFieldSize, formattedTextField.getPreferredSize() );
|
||||
assertEquals( textFieldSize, passwordField.getPreferredSize() );
|
||||
if( testComboBoxAndSpinner )
|
||||
assertEquals( textFieldSize, spinner.getPreferredSize() );
|
||||
assertEquals( textFieldSize, spinner.getPreferredSize() );
|
||||
|
||||
|
||||
// should have same default size (minimumWidth is 72)
|
||||
@@ -84,10 +77,8 @@ public class TestFlatComponentSizes
|
||||
comboBoxEditable.setEditable( true );
|
||||
|
||||
Dimension buttonSize = button.getPreferredSize();
|
||||
if( testComboBoxAndSpinner ) {
|
||||
assertEquals( buttonSize, comboBox.getPreferredSize() );
|
||||
assertEquals( buttonSize, comboBoxEditable.getPreferredSize() );
|
||||
}
|
||||
assertEquals( buttonSize, comboBox.getPreferredSize() );
|
||||
assertEquals( buttonSize, comboBoxEditable.getPreferredSize() );
|
||||
|
||||
|
||||
// should have same height
|
||||
|
||||
@@ -27,6 +27,8 @@ import com.formdev.flatlaf.FlatSystemProperties;
|
||||
*/
|
||||
public class TestUtils
|
||||
{
|
||||
public static final float[] FACTORS = new float[] { 1f, 1.25f, 1.5f, 1.75f, 2f, 2.25f, 2.5f, 2.75f, 3f, 3.25f, 3.5f, 3.75f, 4f, 5f, 6f };
|
||||
|
||||
public static void setup( boolean withFocus ) {
|
||||
System.setProperty( FlatSystemProperties.UI_SCALE, "1x" );
|
||||
if( withFocus )
|
||||
|
||||
Reference in New Issue
Block a user