mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 23:37:13 -06:00
ComboBox: made popup list wider if list item texts are longer than combo box width
This commit is contained in:
@@ -341,6 +341,22 @@ public class FlatComboBoxUI
|
|||||||
super( combo );
|
super( combo );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Rectangle computePopupBounds( int px, int py, int pw, int ph ) {
|
||||||
|
// get maximum display size of all items, ignoring prototype value
|
||||||
|
Object prototype = comboBox.getPrototypeDisplayValue();
|
||||||
|
if( prototype != null )
|
||||||
|
comboBox.setPrototypeDisplayValue( null );
|
||||||
|
Dimension displaySize = getDisplaySize();
|
||||||
|
if( prototype != null )
|
||||||
|
comboBox.setPrototypeDisplayValue( prototype );
|
||||||
|
|
||||||
|
// make popup wider if necessary
|
||||||
|
pw = Math.max( pw, displaySize.width );
|
||||||
|
|
||||||
|
return super.computePopupBounds( px, py, pw, ph );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configurePopup() {
|
protected void configurePopup() {
|
||||||
super.configurePopup();
|
super.configurePopup();
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ public class FlatComponentsTest
|
|||||||
JComboBox<String> comboBox2 = new JComboBox<>();
|
JComboBox<String> comboBox2 = new JComboBox<>();
|
||||||
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<>();
|
||||||
JLabel spinnerLabel = new JLabel();
|
JLabel spinnerLabel = new JLabel();
|
||||||
JSpinner spinner1 = new JSpinner();
|
JSpinner spinner1 = new JSpinner();
|
||||||
JSpinner spinner2 = new JSpinner();
|
JSpinner spinner2 = new JSpinner();
|
||||||
@@ -365,6 +366,16 @@ public class FlatComponentsTest
|
|||||||
comboBox4.setEnabled(false);
|
comboBox4.setEnabled(false);
|
||||||
add(comboBox4, "cell 4 5,growx");
|
add(comboBox4, "cell 4 5,growx");
|
||||||
|
|
||||||
|
//---- comboBox5 ----
|
||||||
|
comboBox5.setPrototypeDisplayValue("12345");
|
||||||
|
comboBox5.setModel(new DefaultComboBoxModel<>(new String[] {
|
||||||
|
"wide popup if text is longer",
|
||||||
|
"aa",
|
||||||
|
"bbb",
|
||||||
|
"cccc"
|
||||||
|
}));
|
||||||
|
add(comboBox5, "cell 5 5,growx");
|
||||||
|
|
||||||
//---- spinnerLabel ----
|
//---- spinnerLabel ----
|
||||||
spinnerLabel.setText("JSpinner:");
|
spinnerLabel.setText("JSpinner:");
|
||||||
add(spinnerLabel, "cell 0 6");
|
add(spinnerLabel, "cell 0 6");
|
||||||
|
|||||||
@@ -240,6 +240,19 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 4 5,growx"
|
"value": "cell 4 5,growx"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JComboBox" ) {
|
||||||
|
name: "comboBox5"
|
||||||
|
"prototypeDisplayValue": "12345"
|
||||||
|
"model": new javax.swing.DefaultComboBoxModel {
|
||||||
|
selectedItem: "wide popup if text is longer"
|
||||||
|
addElement( "wide popup if text is longer" )
|
||||||
|
addElement( "aa" )
|
||||||
|
addElement( "bbb" )
|
||||||
|
addElement( "cccc" )
|
||||||
|
}
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 5 5,growx"
|
||||||
|
} )
|
||||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
name: "spinnerLabel"
|
name: "spinnerLabel"
|
||||||
"text": "JSpinner:"
|
"text": "JSpinner:"
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ class BasicComponentsPanel
|
|||||||
JComboBox<String> comboBox2 = new JComboBox<>();
|
JComboBox<String> comboBox2 = new JComboBox<>();
|
||||||
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<>();
|
||||||
JLabel spinnerLabel = new JLabel();
|
JLabel spinnerLabel = new JLabel();
|
||||||
JSpinner spinner1 = new JSpinner();
|
JSpinner spinner1 = new JSpinner();
|
||||||
JSpinner spinner2 = new JSpinner();
|
JSpinner spinner2 = new JSpinner();
|
||||||
@@ -264,6 +265,16 @@ class BasicComponentsPanel
|
|||||||
comboBox4.setEnabled(false);
|
comboBox4.setEnabled(false);
|
||||||
add(comboBox4, "cell 4 4,growx");
|
add(comboBox4, "cell 4 4,growx");
|
||||||
|
|
||||||
|
//---- comboBox5 ----
|
||||||
|
comboBox5.setPrototypeDisplayValue("12345");
|
||||||
|
comboBox5.setModel(new DefaultComboBoxModel<>(new String[] {
|
||||||
|
"wide popup if text is longer",
|
||||||
|
"aa",
|
||||||
|
"bbb",
|
||||||
|
"cccc"
|
||||||
|
}));
|
||||||
|
add(comboBox5, "cell 5 4,growx");
|
||||||
|
|
||||||
//---- spinnerLabel ----
|
//---- spinnerLabel ----
|
||||||
spinnerLabel.setText("JSpinner:");
|
spinnerLabel.setText("JSpinner:");
|
||||||
add(spinnerLabel, "cell 0 5");
|
add(spinnerLabel, "cell 0 5");
|
||||||
|
|||||||
@@ -199,6 +199,19 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 4 4,growx"
|
"value": "cell 4 4,growx"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JComboBox" ) {
|
||||||
|
name: "comboBox5"
|
||||||
|
"prototypeDisplayValue": "12345"
|
||||||
|
"model": new javax.swing.DefaultComboBoxModel {
|
||||||
|
selectedItem: "wide popup if text is longer"
|
||||||
|
addElement( "wide popup if text is longer" )
|
||||||
|
addElement( "aa" )
|
||||||
|
addElement( "bbb" )
|
||||||
|
addElement( "cccc" )
|
||||||
|
}
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 5 4,growx"
|
||||||
|
} )
|
||||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
name: "spinnerLabel"
|
name: "spinnerLabel"
|
||||||
"text": "JSpinner:"
|
"text": "JSpinner:"
|
||||||
|
|||||||
Reference in New Issue
Block a user