From 659ead903c3faebc7b0c9904e5d80bce117857ad Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Tue, 12 May 2020 18:58:17 +0200 Subject: [PATCH] TextField: avoid garbage in corners if `TextComponent.arc` is set to a large value --- .../flatlaf/ui/FlatPasswordFieldUI.java | 2 +- .../formdev/flatlaf/ui/FlatTextFieldUI.java | 4 +- .../flatlaf/testing/FlatComponentsTest.java | 72 ++++++++++++++++- .../flatlaf/testing/FlatComponentsTest.jfd | 79 ++++++++++++++++++- 4 files changed, 151 insertions(+), 6 deletions(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPasswordFieldUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPasswordFieldUI.java index 96e6f15a..adb1d707 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPasswordFieldUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPasswordFieldUI.java @@ -96,7 +96,7 @@ public class FlatPasswordFieldUI placeholderForeground = UIManager.getColor( prefix + ".placeholderForeground" ); capsLockIcon = UIManager.getIcon( "PasswordField.capsLockIcon" ); - LookAndFeel.installProperty( getComponent(), "opaque", focusWidth == 0 ); + LookAndFeel.installProperty( getComponent(), "opaque", false ); MigLayoutVisualPadding.install( getComponent(), focusWidth ); } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java index e566b07b..1f5173b3 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java @@ -95,7 +95,7 @@ public class FlatTextFieldUI isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" ); placeholderForeground = UIManager.getColor( prefix + ".placeholderForeground" ); - LookAndFeel.installProperty( getComponent(), "opaque", focusWidth == 0 ); + LookAndFeel.installProperty( getComponent(), "opaque", false ); MigLayoutVisualPadding.install( getComponent(), focusWidth ); } @@ -162,7 +162,7 @@ public class FlatTextFieldUI return; // fill background if opaque to avoid garbage if user sets opaque to true - if( c.isOpaque() && focusWidth > 0 ) + if( c.isOpaque() && (focusWidth > 0 || arc > 0) ) FlatUIUtils.paintParentBackground( g, c ); // paint background diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.java index c7767e1d..afe2b1ba 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.java @@ -80,6 +80,7 @@ public class FlatComponentsTest JButton button14 = new JButton(); JButton button15 = new JButton(); JButton button16 = new JButton(); + JButton button20 = new JButton(); JLabel toggleButtonLabel = new JLabel(); JToggleButton toggleButton1 = new JToggleButton(); JToggleButton toggleButton9 = new JToggleButton(); @@ -91,6 +92,7 @@ public class FlatComponentsTest JToggleButton toggleButton12 = new JToggleButton(); JToggleButton toggleButton13 = new JToggleButton(); JToggleButton toggleButton14 = new JToggleButton(); + JToggleButton toggleButton18 = new JToggleButton(); JLabel checkBoxLabel = new JLabel(); JCheckBox checkBox1 = new JCheckBox(); JCheckBox checkBox2 = new JCheckBox(); @@ -110,28 +112,33 @@ public class FlatComponentsTest JComboBox comboBox3 = new JComboBox<>(); JComboBox comboBox4 = new JComboBox<>(); JComboBox comboBox5 = new JComboBox<>(); + JComboBox comboBox6 = new JComboBox<>(); JLabel spinnerLabel = new JLabel(); JSpinner spinner1 = new JSpinner(); JSpinner spinner2 = new JSpinner(); JComboBox comboBox7 = new JComboBox<>(); + JSpinner spinner3 = new JSpinner(); JLabel textFieldLabel = new JLabel(); JTextField textField1 = new JTextField(); JTextField textField2 = new JTextField(); JTextField textField3 = new JTextField(); JTextField textField4 = new JTextField(); JTextField textField6 = new JTextField(); + JTextField textField5 = new JTextField(); JLabel formattedTextFieldLabel = new JLabel(); JFormattedTextField formattedTextField1 = new JFormattedTextField(); JFormattedTextField formattedTextField2 = new JFormattedTextField(); JFormattedTextField formattedTextField3 = new JFormattedTextField(); JFormattedTextField formattedTextField4 = new JFormattedTextField(); JFormattedTextField formattedTextField5 = new JFormattedTextField(); + JFormattedTextField formattedTextField6 = new JFormattedTextField(); JLabel passwordFieldLabel = new JLabel(); JPasswordField passwordField1 = new JPasswordField(); JPasswordField passwordField2 = new JPasswordField(); JPasswordField passwordField3 = new JPasswordField(); JPasswordField passwordField4 = new JPasswordField(); JPasswordField passwordField5 = new JPasswordField(); + JPasswordField passwordField6 = new JPasswordField(); JLabel textAreaLabel = new JLabel(); JScrollPane scrollPane1 = new JScrollPane(); JTextArea textArea1 = new JTextArea(); @@ -181,6 +188,9 @@ public class FlatComponentsTest JButton button10 = new JButton(); JButton button11 = new JButton(); JToggleButton toggleButton7 = new JToggleButton(); + JScrollPane scrollPane15 = new JScrollPane(); + JPanel panel3 = new JPanel(); + JButton button21 = new JButton(); JLabel scrollBarLabel = new JLabel(); JScrollBar scrollBar1 = new JScrollBar(); JScrollBar scrollBar4 = new JScrollBar(); @@ -221,7 +231,8 @@ public class FlatComponentsTest "[]" + "[]" + "[]" + - "[]", + "[]" + + "[left]", // rows "[]" + "[]" + @@ -326,6 +337,11 @@ public class FlatComponentsTest button16.setText("#"); add(button16, "cell 5 1"); + //---- button20 ---- + button20.setText("empty border"); + button20.setBorder(BorderFactory.createEmptyBorder()); + add(button20, "cell 6 1"); + //---- toggleButtonLabel ---- toggleButtonLabel.setText("JToggleButton:"); add(toggleButtonLabel, "cell 0 2"); @@ -381,6 +397,11 @@ public class FlatComponentsTest toggleButton14.setSelected(true); add(toggleButton14, "cell 5 2"); + //---- toggleButton18 ---- + toggleButton18.setText("empty border"); + toggleButton18.setBorder(BorderFactory.createEmptyBorder()); + add(toggleButton18, "cell 6 2"); + //---- checkBoxLabel ---- checkBoxLabel.setText("JCheckBox"); add(checkBoxLabel, "cell 0 3"); @@ -521,6 +542,16 @@ public class FlatComponentsTest })); add(comboBox5, "cell 5 5,growx,wmax 100"); + //---- comboBox6 ---- + comboBox6.setBorder(BorderFactory.createEmptyBorder()); + comboBox6.setModel(new DefaultComboBoxModel<>(new String[] { + "empty border", + "a", + "b", + "c" + })); + add(comboBox6, "cell 6 5"); + //---- spinnerLabel ---- spinnerLabel.setText("JSpinner:"); add(spinnerLabel, "cell 0 6"); @@ -535,6 +566,11 @@ public class FlatComponentsTest comboBox7.putClientProperty("JTextField.placeholderText", "placeholder"); add(comboBox7, "cell 5 6,growx"); + //---- spinner3 ---- + spinner3.setBorder(BorderFactory.createEmptyBorder()); + spinner3.setModel(new SpinnerNumberModel(12345, null, null, 1)); + add(spinner3, "cell 6 6"); + //---- textFieldLabel ---- textFieldLabel.setText("JTextField:"); add(textFieldLabel, "cell 0 7"); @@ -563,6 +599,11 @@ public class FlatComponentsTest textField6.putClientProperty("JTextField.placeholderText", "placeholder"); add(textField6, "cell 5 7,growx"); + //---- textField5 ---- + textField5.setText("empty border"); + textField5.setBorder(BorderFactory.createEmptyBorder()); + add(textField5, "cell 6 7"); + //---- formattedTextFieldLabel ---- formattedTextFieldLabel.setText("JFormattedTextField:"); add(formattedTextFieldLabel, "cell 0 8"); @@ -591,6 +632,11 @@ public class FlatComponentsTest formattedTextField5.putClientProperty("JTextField.placeholderText", "placeholder"); add(formattedTextField5, "cell 5 8,growx"); + //---- formattedTextField6 ---- + formattedTextField6.setText("empty border"); + formattedTextField6.setBorder(BorderFactory.createEmptyBorder()); + add(formattedTextField6, "cell 6 8"); + //---- passwordFieldLabel ---- passwordFieldLabel.setText("JPasswordField:"); add(passwordFieldLabel, "cell 0 9"); @@ -619,6 +665,11 @@ public class FlatComponentsTest passwordField5.putClientProperty("JTextField.placeholderText", "placeholder"); add(passwordField5, "cell 5 9,growx"); + //---- passwordField6 ---- + passwordField6.setText("empty border"); + passwordField6.setBorder(BorderFactory.createEmptyBorder()); + add(passwordField6, "cell 6 9"); + //---- textAreaLabel ---- textAreaLabel.setText("JTextArea:"); add(textAreaLabel, "cell 0 10"); @@ -883,6 +934,25 @@ public class FlatComponentsTest } add(toolBar2, "cell 4 13 1 6,growy"); + //======== scrollPane15 ======== + { + scrollPane15.setBorder(BorderFactory.createEmptyBorder()); + + //======== panel3 ======== + { + panel3.setPreferredSize(new Dimension(800, 400)); + panel3.setLayout(new BorderLayout()); + + //---- button21 ---- + button21.setText("I'm a large button in a scrollpane with empty border"); + button21.setVerticalAlignment(SwingConstants.TOP); + button21.setHorizontalAlignment(SwingConstants.LEFT); + panel3.add(button21, BorderLayout.CENTER); + } + scrollPane15.setViewportView(panel3); + } + add(scrollPane15, "cell 6 13,growy,width 100,height 50"); + //---- scrollBarLabel ---- scrollBarLabel.setText("JScrollBar:"); add(scrollBarLabel, "cell 0 14"); diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.jfd b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.jfd index 1daebf5f..defe66fa 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.jfd +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.jfd @@ -1,4 +1,4 @@ -JFDML JFormDesigner: "7.0.1.0.272" Java: "13.0.1" encoding: "UTF-8" +JFDML JFormDesigner: "7.0.1.0.272" Java: "13.0.2" encoding: "UTF-8" new FormModel { contentType: "form/swing" @@ -8,7 +8,7 @@ new FormModel { } add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { "$layoutConstraints": "ltr,insets dialog,hidemode 3" - "$columnConstraints": "[][][][][][]" + "$columnConstraints": "[][][][][][][left]" "$rowConstraints": "[][][][][][][][][][][][][][][][][][][][][][][][]" } ) { name: "this" @@ -120,6 +120,13 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 5 1" } ) + add( new FormComponent( "javax.swing.JButton" ) { + name: "button20" + "text": "empty border" + "border": &EmptyBorder0 new javax.swing.border.EmptyBorder( 0, 0, 0, 0 ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 6 1" + } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "toggleButtonLabel" "text": "JToggleButton:" @@ -197,6 +204,13 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 5 2" } ) + add( new FormComponent( "javax.swing.JToggleButton" ) { + name: "toggleButton18" + "text": "empty border" + "border": #EmptyBorder0 + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 6 2" + } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "checkBoxLabel" "text": "JCheckBox" @@ -383,6 +397,19 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 5 5,growx,wmax 100" } ) + add( new FormComponent( "javax.swing.JComboBox" ) { + name: "comboBox6" + "border": #EmptyBorder0 + "model": new javax.swing.DefaultComboBoxModel { + selectedItem: "empty border" + addElement( "empty border" ) + addElement( "a" ) + addElement( "b" ) + addElement( "c" ) + } + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 6 5" + } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "spinnerLabel" "text": "JSpinner:" @@ -410,6 +437,15 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 5 6,growx" } ) + add( new FormComponent( "javax.swing.JSpinner" ) { + name: "spinner3" + "border": new javax.swing.border.EmptyBorder( 0, 0, 0, 0 ) + "model": new javax.swing.SpinnerNumberModel { + value: 12345 + } + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 6 6" + } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "textFieldLabel" "text": "JTextField:" @@ -450,6 +486,13 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 5 7,growx" } ) + add( new FormComponent( "javax.swing.JTextField" ) { + name: "textField5" + "text": "empty border" + "border": #EmptyBorder0 + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 6 7" + } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "formattedTextFieldLabel" "text": "JFormattedTextField:" @@ -490,6 +533,13 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 5 8,growx" } ) + add( new FormComponent( "javax.swing.JFormattedTextField" ) { + name: "formattedTextField6" + "text": "empty border" + "border": #EmptyBorder0 + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 6 8" + } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "passwordFieldLabel" "text": "JPasswordField:" @@ -530,6 +580,13 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 5 9,growx" } ) + add( new FormComponent( "javax.swing.JPasswordField" ) { + name: "passwordField6" + "text": "empty border" + "border": #EmptyBorder0 + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 6 9" + } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "textAreaLabel" "text": "JTextArea:" @@ -839,6 +896,24 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 4 13 1 6,growy" } ) + add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { + name: "scrollPane15" + "border": new javax.swing.border.EmptyBorder( 0, 0, 0, 0 ) + add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.BorderLayout ) ) { + name: "panel3" + "preferredSize": new java.awt.Dimension( 800, 400 ) + add( new FormComponent( "javax.swing.JButton" ) { + name: "button21" + "text": "I'm a large button in a scrollpane with empty border" + "verticalAlignment": 1 + "horizontalAlignment": 2 + }, new FormLayoutConstraints( class java.lang.String ) { + "value": "Center" + } ) + } ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 6 13,growy,width 100,height 50" + } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "scrollBarLabel" "text": "JScrollBar:"