ComboBox: if using own JTextField as editor, default text field border is now removed to avoid duplicate border

This commit is contained in:
Karl Tauber
2020-09-24 22:17:10 +02:00
parent a4ddc13c1a
commit dfd6831b02
4 changed files with 61 additions and 4 deletions

View File

@@ -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

View File

@@ -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 );

View File

@@ -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<String> 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<String> comboBox12;
private JComboBox<String> comboBox17;
private JComboBox<String> comboBox19;
private JComboBox<String> comboBox21;
private JComboBox<String> comboBox13;
private JComboBox<String> comboBox14;
private JComboBox<String> comboBox15;
private JComboBox<String> comboBox16;
private JComboBox<String> comboBox18;
private JComboBox<String> comboBox20;
private JComboBox<String> comboBox22;
private JLabel label6;
private JSpinner spinner1;
private JSpinner spinner2;

View File

@@ -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 )
} )
}
}