It seems that the JComboBox is one Java component that really, really hates having its height adjusted...I tried countless combinations of set[Preferred|Minimum|Maximum]Size()
and various different layout managers until the following GroupLayout
code finally worked:
JComboBox cmbCategories = new JComboBox(new String[] { "Category 1", "Category 2" });
...
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(cmbCategories, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
...
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(cmbCategories, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
But I've now switched over to JGoodies FormLayout
which once again refuses to resize the damn combobox! I've currently got the following code:
JPanel contentPane = new JPanel();
contentPane.setLayout(new FormLayout("50dlu, $lcgap, 110dlu, $glue, " +
"default, 1dlu, 45dlu, 1dlu, 45dlu", "2*(default, 0dlu), default, " +
"$lgap, fill:30dlu, $lgap, default:grow"));
...
contentPane.add(cmbPanel, CC.xy(1, 7, CC.FILL, CC.FILL));
which displays what I want in the JFormDesigner Editor, but upon running the program it simply gets set back to the default!
So what kind of magical hocus-pocus do I need to conjure up to get this to work?! I really don't want to have to go back to defining everything twice in a GroupLayout
, but after 5 hours of trying to resize a damn combobox I'm on the verge of baldness!
MTIA to anyone that can help :)