UI Designer JComboBox model

I designed a form using the UI designer and the form contains many JComboBoxes which should allow the user to select items in different Enums.

To allow this I want to set a custom ComboBoxModel on the JComboBoxes. I checked the JComboBox as "Custom Create" and I initialize the JComboBox using:

orientation = new JComboBox(new EnumComboBoxModel]]>(PageOrientation.class));

I expected this to work, but there is nothing showing when running the form. I decompiled the form and found out that in the $$$setup$$$ method it is overwritten:

JComboBox jcombobox2 = orientation;
DefaultComboBoxModel defaultcomboboxmodel2;
jcombobox2.setModel(defaultcomboboxmodel2 = new DefaultComboBoxModel());

Is there a way to fix this.

3 comments

A workaround would be to let the UI designer create the comboboxes and then set your custom model after the $$$setup$$$ method has been executed.

0

Hello Bart,

I designed a form using the UI designer and the form contains many
JComboBoxes which should allow the user to select items in different
Enums.

To allow this I want to set a custom ComboBoxModel on the JComboBoxes.
I checked the JComboBox as "Custom Create" and I initialize the
JComboBox using:

orientation = new JComboBox(new
EnumComboBoxModel<PageOrientation>(PageOrientation.class));

I expected this to work, but there is nothing showing when running the
form. I decompiled the form and found out that in the $$$setup$$$
method it is overwritten:

JComboBox jcombobox2 = orientation;
DefaultComboBoxModel defaultcomboboxmodel2;
jcombobox2.setModel(defaultcomboboxmodel2 = new
DefaultComboBoxModel());
Is there a way to fix this.


Select the "model" property of the combobox in the property inspector and
invoke "Restore Default Value" from the context menu. Then the UI Designer
will no longer generate code for setting the model./

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Restoring the default value did the trick.

0

Please sign in to leave a comment.