I'm trying to use GridBagLayout
to position labels in two rows, but I want some of the labels to span both rows and others to be placed on top of each other. I need to use GridBagLayout
because of the proportional sizing functionality in the weightx
and weighty
properties of GridBagConstraints
. This is the layout I'm looking for:
+----------+----------+----------+----------+ | | | labelC | | | labelA | labelB |----------| labelD | | | | labelE | | +----------+----------+----------+----------+
The problem is that labelE
is being placed beneath LabelA
. Here is the layout portion of my code:
GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); this.setLayout(gridBag); c.fill = GridBagConstraints.BOTH; c.gridwidth = 1; c.gridheight = 2; c.weighty = PANEL_HEIGHT; gridbag.setConstraints(labelA, c); this.add(labelA); gridbag.setConstraints(labelB, c); this.add(labelB); c.gridheight = 1; c.weighty = TOPROW_HEIGHT; gridbag.setConstraints(labelC, c); this.add(labelC); c.gridheight = 2; c.gridwidth = GridBagConstraints.REMAINDER; c.weighty = PANEL_HEIGHT; gridbag.setConstraints(labelD, c); this.add(labelD); c.gridheight = 1; c.gridwidth = 1; c.weighty = BOTROW_HEIGHT; gridbag.setConstraints(labelE, c); this.add(labelE); this.validate();
Any ideas about what I'm missing?