ComboBox: made popup list wider if list item texts are longer than combo box width

This commit is contained in:
Karl Tauber
2019-09-26 10:35:19 +02:00
parent 84dc96d41a
commit fbfde043b3
5 changed files with 64 additions and 0 deletions

View File

@@ -54,6 +54,7 @@ class BasicComponentsPanel
JComboBox<String> comboBox2 = new JComboBox<>();
JComboBox<String> comboBox3 = new JComboBox<>();
JComboBox<String> comboBox4 = new JComboBox<>();
JComboBox<String> comboBox5 = new JComboBox<>();
JLabel spinnerLabel = new JLabel();
JSpinner spinner1 = new JSpinner();
JSpinner spinner2 = new JSpinner();
@@ -264,6 +265,16 @@ class BasicComponentsPanel
comboBox4.setEnabled(false);
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.setText("JSpinner:");
add(spinnerLabel, "cell 0 5");

View File

@@ -199,6 +199,19 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"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" ) {
name: "spinnerLabel"
"text": "JSpinner:"