TextField: avoid garbage in corners if TextComponent.arc is set to a large value

This commit is contained in:
Karl Tauber
2020-05-12 18:58:17 +02:00
parent 070c435f40
commit 659ead903c
4 changed files with 151 additions and 6 deletions

View File

@@ -96,7 +96,7 @@ public class FlatPasswordFieldUI
placeholderForeground = UIManager.getColor( prefix + ".placeholderForeground" ); placeholderForeground = UIManager.getColor( prefix + ".placeholderForeground" );
capsLockIcon = UIManager.getIcon( "PasswordField.capsLockIcon" ); capsLockIcon = UIManager.getIcon( "PasswordField.capsLockIcon" );
LookAndFeel.installProperty( getComponent(), "opaque", focusWidth == 0 ); LookAndFeel.installProperty( getComponent(), "opaque", false );
MigLayoutVisualPadding.install( getComponent(), focusWidth ); MigLayoutVisualPadding.install( getComponent(), focusWidth );
} }

View File

@@ -95,7 +95,7 @@ public class FlatTextFieldUI
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" ); isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
placeholderForeground = UIManager.getColor( prefix + ".placeholderForeground" ); placeholderForeground = UIManager.getColor( prefix + ".placeholderForeground" );
LookAndFeel.installProperty( getComponent(), "opaque", focusWidth == 0 ); LookAndFeel.installProperty( getComponent(), "opaque", false );
MigLayoutVisualPadding.install( getComponent(), focusWidth ); MigLayoutVisualPadding.install( getComponent(), focusWidth );
} }
@@ -162,7 +162,7 @@ public class FlatTextFieldUI
return; return;
// fill background if opaque to avoid garbage if user sets opaque to true // 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 ); FlatUIUtils.paintParentBackground( g, c );
// paint background // paint background

View File

@@ -80,6 +80,7 @@ public class FlatComponentsTest
JButton button14 = new JButton(); JButton button14 = new JButton();
JButton button15 = new JButton(); JButton button15 = new JButton();
JButton button16 = new JButton(); JButton button16 = new JButton();
JButton button20 = new JButton();
JLabel toggleButtonLabel = new JLabel(); JLabel toggleButtonLabel = new JLabel();
JToggleButton toggleButton1 = new JToggleButton(); JToggleButton toggleButton1 = new JToggleButton();
JToggleButton toggleButton9 = new JToggleButton(); JToggleButton toggleButton9 = new JToggleButton();
@@ -91,6 +92,7 @@ public class FlatComponentsTest
JToggleButton toggleButton12 = new JToggleButton(); JToggleButton toggleButton12 = new JToggleButton();
JToggleButton toggleButton13 = new JToggleButton(); JToggleButton toggleButton13 = new JToggleButton();
JToggleButton toggleButton14 = new JToggleButton(); JToggleButton toggleButton14 = new JToggleButton();
JToggleButton toggleButton18 = new JToggleButton();
JLabel checkBoxLabel = new JLabel(); JLabel checkBoxLabel = new JLabel();
JCheckBox checkBox1 = new JCheckBox(); JCheckBox checkBox1 = new JCheckBox();
JCheckBox checkBox2 = new JCheckBox(); JCheckBox checkBox2 = new JCheckBox();
@@ -110,28 +112,33 @@ public class FlatComponentsTest
JComboBox<String> comboBox3 = new JComboBox<>(); JComboBox<String> comboBox3 = new JComboBox<>();
JComboBox<String> comboBox4 = new JComboBox<>(); JComboBox<String> comboBox4 = new JComboBox<>();
JComboBox<String> comboBox5 = new JComboBox<>(); JComboBox<String> comboBox5 = new JComboBox<>();
JComboBox<String> comboBox6 = new JComboBox<>();
JLabel spinnerLabel = new JLabel(); JLabel spinnerLabel = new JLabel();
JSpinner spinner1 = new JSpinner(); JSpinner spinner1 = new JSpinner();
JSpinner spinner2 = new JSpinner(); JSpinner spinner2 = new JSpinner();
JComboBox<String> comboBox7 = new JComboBox<>(); JComboBox<String> comboBox7 = new JComboBox<>();
JSpinner spinner3 = new JSpinner();
JLabel textFieldLabel = new JLabel(); JLabel textFieldLabel = new JLabel();
JTextField textField1 = new JTextField(); JTextField textField1 = new JTextField();
JTextField textField2 = new JTextField(); JTextField textField2 = new JTextField();
JTextField textField3 = new JTextField(); JTextField textField3 = new JTextField();
JTextField textField4 = new JTextField(); JTextField textField4 = new JTextField();
JTextField textField6 = new JTextField(); JTextField textField6 = new JTextField();
JTextField textField5 = new JTextField();
JLabel formattedTextFieldLabel = new JLabel(); JLabel formattedTextFieldLabel = new JLabel();
JFormattedTextField formattedTextField1 = new JFormattedTextField(); JFormattedTextField formattedTextField1 = new JFormattedTextField();
JFormattedTextField formattedTextField2 = new JFormattedTextField(); JFormattedTextField formattedTextField2 = new JFormattedTextField();
JFormattedTextField formattedTextField3 = new JFormattedTextField(); JFormattedTextField formattedTextField3 = new JFormattedTextField();
JFormattedTextField formattedTextField4 = new JFormattedTextField(); JFormattedTextField formattedTextField4 = new JFormattedTextField();
JFormattedTextField formattedTextField5 = new JFormattedTextField(); JFormattedTextField formattedTextField5 = new JFormattedTextField();
JFormattedTextField formattedTextField6 = new JFormattedTextField();
JLabel passwordFieldLabel = new JLabel(); JLabel passwordFieldLabel = new JLabel();
JPasswordField passwordField1 = new JPasswordField(); JPasswordField passwordField1 = new JPasswordField();
JPasswordField passwordField2 = new JPasswordField(); JPasswordField passwordField2 = new JPasswordField();
JPasswordField passwordField3 = new JPasswordField(); JPasswordField passwordField3 = new JPasswordField();
JPasswordField passwordField4 = new JPasswordField(); JPasswordField passwordField4 = new JPasswordField();
JPasswordField passwordField5 = new JPasswordField(); JPasswordField passwordField5 = new JPasswordField();
JPasswordField passwordField6 = new JPasswordField();
JLabel textAreaLabel = new JLabel(); JLabel textAreaLabel = new JLabel();
JScrollPane scrollPane1 = new JScrollPane(); JScrollPane scrollPane1 = new JScrollPane();
JTextArea textArea1 = new JTextArea(); JTextArea textArea1 = new JTextArea();
@@ -181,6 +188,9 @@ public class FlatComponentsTest
JButton button10 = new JButton(); JButton button10 = new JButton();
JButton button11 = new JButton(); JButton button11 = new JButton();
JToggleButton toggleButton7 = new JToggleButton(); JToggleButton toggleButton7 = new JToggleButton();
JScrollPane scrollPane15 = new JScrollPane();
JPanel panel3 = new JPanel();
JButton button21 = new JButton();
JLabel scrollBarLabel = new JLabel(); JLabel scrollBarLabel = new JLabel();
JScrollBar scrollBar1 = new JScrollBar(); JScrollBar scrollBar1 = new JScrollBar();
JScrollBar scrollBar4 = new JScrollBar(); JScrollBar scrollBar4 = new JScrollBar();
@@ -221,7 +231,8 @@ public class FlatComponentsTest
"[]" + "[]" +
"[]" + "[]" +
"[]" + "[]" +
"[]", "[]" +
"[left]",
// rows // rows
"[]" + "[]" +
"[]" + "[]" +
@@ -326,6 +337,11 @@ public class FlatComponentsTest
button16.setText("#"); button16.setText("#");
add(button16, "cell 5 1"); add(button16, "cell 5 1");
//---- button20 ----
button20.setText("empty border");
button20.setBorder(BorderFactory.createEmptyBorder());
add(button20, "cell 6 1");
//---- toggleButtonLabel ---- //---- toggleButtonLabel ----
toggleButtonLabel.setText("JToggleButton:"); toggleButtonLabel.setText("JToggleButton:");
add(toggleButtonLabel, "cell 0 2"); add(toggleButtonLabel, "cell 0 2");
@@ -381,6 +397,11 @@ public class FlatComponentsTest
toggleButton14.setSelected(true); toggleButton14.setSelected(true);
add(toggleButton14, "cell 5 2"); add(toggleButton14, "cell 5 2");
//---- toggleButton18 ----
toggleButton18.setText("empty border");
toggleButton18.setBorder(BorderFactory.createEmptyBorder());
add(toggleButton18, "cell 6 2");
//---- checkBoxLabel ---- //---- checkBoxLabel ----
checkBoxLabel.setText("JCheckBox"); checkBoxLabel.setText("JCheckBox");
add(checkBoxLabel, "cell 0 3"); add(checkBoxLabel, "cell 0 3");
@@ -521,6 +542,16 @@ public class FlatComponentsTest
})); }));
add(comboBox5, "cell 5 5,growx,wmax 100"); 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 ----
spinnerLabel.setText("JSpinner:"); spinnerLabel.setText("JSpinner:");
add(spinnerLabel, "cell 0 6"); add(spinnerLabel, "cell 0 6");
@@ -535,6 +566,11 @@ public class FlatComponentsTest
comboBox7.putClientProperty("JTextField.placeholderText", "placeholder"); comboBox7.putClientProperty("JTextField.placeholderText", "placeholder");
add(comboBox7, "cell 5 6,growx"); 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 ----
textFieldLabel.setText("JTextField:"); textFieldLabel.setText("JTextField:");
add(textFieldLabel, "cell 0 7"); add(textFieldLabel, "cell 0 7");
@@ -563,6 +599,11 @@ public class FlatComponentsTest
textField6.putClientProperty("JTextField.placeholderText", "placeholder"); textField6.putClientProperty("JTextField.placeholderText", "placeholder");
add(textField6, "cell 5 7,growx"); add(textField6, "cell 5 7,growx");
//---- textField5 ----
textField5.setText("empty border");
textField5.setBorder(BorderFactory.createEmptyBorder());
add(textField5, "cell 6 7");
//---- formattedTextFieldLabel ---- //---- formattedTextFieldLabel ----
formattedTextFieldLabel.setText("JFormattedTextField:"); formattedTextFieldLabel.setText("JFormattedTextField:");
add(formattedTextFieldLabel, "cell 0 8"); add(formattedTextFieldLabel, "cell 0 8");
@@ -591,6 +632,11 @@ public class FlatComponentsTest
formattedTextField5.putClientProperty("JTextField.placeholderText", "placeholder"); formattedTextField5.putClientProperty("JTextField.placeholderText", "placeholder");
add(formattedTextField5, "cell 5 8,growx"); add(formattedTextField5, "cell 5 8,growx");
//---- formattedTextField6 ----
formattedTextField6.setText("empty border");
formattedTextField6.setBorder(BorderFactory.createEmptyBorder());
add(formattedTextField6, "cell 6 8");
//---- passwordFieldLabel ---- //---- passwordFieldLabel ----
passwordFieldLabel.setText("JPasswordField:"); passwordFieldLabel.setText("JPasswordField:");
add(passwordFieldLabel, "cell 0 9"); add(passwordFieldLabel, "cell 0 9");
@@ -619,6 +665,11 @@ public class FlatComponentsTest
passwordField5.putClientProperty("JTextField.placeholderText", "placeholder"); passwordField5.putClientProperty("JTextField.placeholderText", "placeholder");
add(passwordField5, "cell 5 9,growx"); add(passwordField5, "cell 5 9,growx");
//---- passwordField6 ----
passwordField6.setText("empty border");
passwordField6.setBorder(BorderFactory.createEmptyBorder());
add(passwordField6, "cell 6 9");
//---- textAreaLabel ---- //---- textAreaLabel ----
textAreaLabel.setText("JTextArea:"); textAreaLabel.setText("JTextArea:");
add(textAreaLabel, "cell 0 10"); add(textAreaLabel, "cell 0 10");
@@ -883,6 +934,25 @@ public class FlatComponentsTest
} }
add(toolBar2, "cell 4 13 1 6,growy"); 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 ----
scrollBarLabel.setText("JScrollBar:"); scrollBarLabel.setText("JScrollBar:");
add(scrollBarLabel, "cell 0 14"); add(scrollBarLabel, "cell 0 14");

View File

@@ -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 { new FormModel {
contentType: "form/swing" contentType: "form/swing"
@@ -8,7 +8,7 @@ new FormModel {
} }
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "ltr,insets dialog,hidemode 3" "$layoutConstraints": "ltr,insets dialog,hidemode 3"
"$columnConstraints": "[][][][][][]" "$columnConstraints": "[][][][][][][left]"
"$rowConstraints": "[][][][][][][][][][][][][][][][][][][][][][][][]" "$rowConstraints": "[][][][][][][][][][][][][][][][][][][][][][][][]"
} ) { } ) {
name: "this" name: "this"
@@ -120,6 +120,13 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 1" "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" ) { add( new FormComponent( "javax.swing.JLabel" ) {
name: "toggleButtonLabel" name: "toggleButtonLabel"
"text": "JToggleButton:" "text": "JToggleButton:"
@@ -197,6 +204,13 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 2" "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" ) { add( new FormComponent( "javax.swing.JLabel" ) {
name: "checkBoxLabel" name: "checkBoxLabel"
"text": "JCheckBox" "text": "JCheckBox"
@@ -383,6 +397,19 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 5,growx,wmax 100" "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" ) { add( new FormComponent( "javax.swing.JLabel" ) {
name: "spinnerLabel" name: "spinnerLabel"
"text": "JSpinner:" "text": "JSpinner:"
@@ -410,6 +437,15 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 6,growx" "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" ) { add( new FormComponent( "javax.swing.JLabel" ) {
name: "textFieldLabel" name: "textFieldLabel"
"text": "JTextField:" "text": "JTextField:"
@@ -450,6 +486,13 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 7,growx" "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" ) { add( new FormComponent( "javax.swing.JLabel" ) {
name: "formattedTextFieldLabel" name: "formattedTextFieldLabel"
"text": "JFormattedTextField:" "text": "JFormattedTextField:"
@@ -490,6 +533,13 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 8,growx" "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" ) { add( new FormComponent( "javax.swing.JLabel" ) {
name: "passwordFieldLabel" name: "passwordFieldLabel"
"text": "JPasswordField:" "text": "JPasswordField:"
@@ -530,6 +580,13 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 9,growx" "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" ) { add( new FormComponent( "javax.swing.JLabel" ) {
name: "textAreaLabel" name: "textAreaLabel"
"text": "JTextArea:" "text": "JTextArea:"
@@ -839,6 +896,24 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 13 1 6,growy" "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" ) { add( new FormComponent( "javax.swing.JLabel" ) {
name: "scrollBarLabel" name: "scrollBarLabel"
"text": "JScrollBar:" "text": "JScrollBar:"