From dfd6831b023b016f3b292048672b0f8eacc821e9 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Thu, 24 Sep 2020 22:17:10 +0200 Subject: [PATCH] ComboBox: if using own `JTextField` as editor, default text field border is now removed to avoid duplicate border --- CHANGELOG.md | 5 +++ .../formdev/flatlaf/ui/FlatComboBoxUI.java | 4 +++ .../testing/FlatCustomBordersTest.java | 25 ++++++++++++++- .../flatlaf/testing/FlatCustomBordersTest.jfd | 31 +++++++++++++++++-- 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53942136..4237465e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ FlatLaf Change Log - TabbedPane: Support hiding separator between tabs and content area (set client property `JTabbedPane.showContentSeparator` to `false`). +#### Fixed bugs + +- ComboBox: If using own `JTextField` as editor, default text field border is + now removed to avoid duplicate border. + ## 0.42 diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java index 471cc905..f41d935b 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java @@ -298,6 +298,10 @@ public class FlatComboBoxUI protected void configureEditor() { super.configureEditor(); + // remove default text field border from editor + if( editor instanceof JTextField && ((JTextField)editor).getBorder() instanceof FlatTextBorder ) + ((JTextField)editor).setBorder( BorderFactory.createEmptyBorder() ); + // explicitly make non-opaque if( editor instanceof JComponent ) ((JComponent)editor).setOpaque( false ); diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatCustomBordersTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatCustomBordersTest.java index a8adc5f3..18c5a0cb 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatCustomBordersTest.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatCustomBordersTest.java @@ -97,6 +97,8 @@ public class FlatCustomBordersTest applyCustomComboBoxEditorBorder( comboBox18 ); applyCustomComboBoxEditorBorderWithIcon( comboBox19 ); applyCustomComboBoxEditorBorderWithIcon( comboBox20 ); + applyCustomComboBoxEditorBorder( comboBox21, null ); + applyCustomComboBoxEditorBorder( comboBox22, null ); } private void applyCustomInsideBorder( JComponent c, String uiKey ) { @@ -117,7 +119,8 @@ public class FlatCustomBordersTest private void applyCustomComboBoxEditorBorder( JComboBox comboBox, Border border ) { JTextField customTextField = new JTextField(); - customTextField.setBorder( border ); + if( border != null ) + customTextField.setBorder( border ); comboBox.setEditor( new BasicComboBoxEditor() { @Override protected JTextField createEditorComponent() { @@ -134,6 +137,7 @@ public class FlatCustomBordersTest label2 = new JLabel(); label8 = new JLabel(); label9 = new JLabel(); + label10 = new JLabel(); label7 = new JLabel(); button1 = new JButton(); button2 = new JButton(); @@ -158,12 +162,14 @@ public class FlatCustomBordersTest comboBox12 = new JComboBox<>(); comboBox17 = new JComboBox<>(); comboBox19 = new JComboBox<>(); + comboBox21 = new JComboBox<>(); comboBox13 = new JComboBox<>(); comboBox14 = new JComboBox<>(); comboBox15 = new JComboBox<>(); comboBox16 = new JComboBox<>(); comboBox18 = new JComboBox<>(); comboBox20 = new JComboBox<>(); + comboBox22 = new JComboBox<>(); label6 = new JLabel(); spinner1 = new JSpinner(); spinner2 = new JSpinner(); @@ -193,6 +199,7 @@ public class FlatCustomBordersTest "[fill]" + "[fill]" + "[fill]" + + "[fill]" + "[fill]", // rows "[]" + @@ -231,6 +238,10 @@ public class FlatCustomBordersTest label9.setText("with icon"); add(label9, "cell 6 0"); + //---- label10 ---- + label10.setText("with default border"); + add(label10, "cell 7 0"); + //---- label7 ---- label7.setText("JButton:"); add(label7, "cell 0 1"); @@ -319,6 +330,10 @@ public class FlatCustomBordersTest comboBox19.setEditable(true); add(comboBox19, "cell 6 5"); + //---- comboBox21 ---- + comboBox21.setEditable(true); + add(comboBox21, "cell 7 5"); + //---- comboBox13 ---- comboBox13.putClientProperty("JComponent.roundRect", true); comboBox13.setEditable(true); @@ -349,6 +364,11 @@ public class FlatCustomBordersTest comboBox20.setEditable(true); add(comboBox20, "cell 6 6"); + //---- comboBox22 ---- + comboBox22.putClientProperty("JComponent.roundRect", true); + comboBox22.setEditable(true); + add(comboBox22, "cell 7 6"); + //---- label6 ---- label6.setText("JSpinner:"); add(label6, "cell 0 7"); @@ -425,6 +445,7 @@ public class FlatCustomBordersTest private JLabel label2; private JLabel label8; private JLabel label9; + private JLabel label10; private JLabel label7; private JButton button1; private JButton button2; @@ -449,12 +470,14 @@ public class FlatCustomBordersTest private JComboBox comboBox12; private JComboBox comboBox17; private JComboBox comboBox19; + private JComboBox comboBox21; private JComboBox comboBox13; private JComboBox comboBox14; private JComboBox comboBox15; private JComboBox comboBox16; private JComboBox comboBox18; private JComboBox comboBox20; + private JComboBox comboBox22; private JLabel label6; private JSpinner spinner1; private JSpinner spinner2; diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatCustomBordersTest.jfd b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatCustomBordersTest.jfd index 90c0460a..36dea94b 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatCustomBordersTest.jfd +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatCustomBordersTest.jfd @@ -1,11 +1,11 @@ -JFDML JFormDesigner: "7.0.1.0.272" Java: "13.0.2" encoding: "UTF-8" +JFDML JFormDesigner: "7.0.2.0.298" Java: "15" encoding: "UTF-8" new FormModel { contentType: "form/swing" root: new FormRoot { add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { "$layoutConstraints": "ltr,insets dialog,hidemode 3" - "$columnConstraints": "[][fill][fill][fill][fill][fill][fill]" + "$columnConstraints": "[][fill][fill][fill][fill][fill][fill][fill]" "$rowConstraints": "[][][][][][][][][][][]" } ) { name: "this" @@ -45,6 +45,12 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 6 0" } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "label10" + "text": "with default border" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 7 0" + } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "label7" "text": "JButton:" @@ -231,6 +237,15 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 6 5" } ) + add( new FormComponent( "javax.swing.JComboBox" ) { + name: "comboBox21" + "editable": true + auxiliary() { + "JavaCodeGenerator.typeParameters": "String" + } + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 7 5" + } ) add( new FormComponent( "javax.swing.JComboBox" ) { name: "comboBox13" "$client.JComponent.roundRect": true @@ -291,6 +306,16 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 6 6" } ) + add( new FormComponent( "javax.swing.JComboBox" ) { + name: "comboBox22" + "$client.JComponent.roundRect": true + "editable": true + auxiliary() { + "JavaCodeGenerator.typeParameters": "String" + } + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 7 6" + } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "label6" "text": "JSpinner:" @@ -404,7 +429,7 @@ new FormModel { } ) }, new FormLayoutConstraints( null ) { "location": new java.awt.Point( 0, 0 ) - "size": new java.awt.Dimension( 790, 715 ) + "size": new java.awt.Dimension( 915, 715 ) } ) } }