I am trying to arrange two set of buttons for a calculator GUI. Each one uses a GroupLayout to make them. One set is the numbers (and "."), the other is for operation buttons. This basically works but if one of the buttons has double length (for example the equals button on my operations set) it throws the other buttons out of line. I will use the operations set as an example. There are two columns and four rows of buttons. The final row only has one button - the equals. I want to make this double length stretching across both columns. At the moment it simply pushes the second column along to the end of it when I want the second column to sit on top of it.
Here's the code for the layout - operLayout is the name of the layout for the operations, left and right brackets on the first row, + and - on the second, * and / on the third and equals on the last row. Each button has a minimumSize set elsewhere (they are all the same except equals is twice as long).
operLayout.setAutoCreateGaps(true);
operLayout.setAutoCreateContainerGaps(true);
operLayout.setVerticalGroup(operLayout
.createSequentialGroup()
.addGroup(
operLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(leftBracket)
.addComponent(rightBracket))
.addGroup(operLayout.createParallelGroup().addComponent(add).addComponent(subtract))
.addGroup(operLayout.createParallelGroup().addComponent(multiply).addComponent(divide))
.addGroup(operLayout.createParallelGroup().addComponent(equals)));
operLayout.setHorizontalGroup(operLayout
.createSequentialGroup()
.addGroup(
operLayout.createParallelGroup().addComponent(leftBracket).addComponent(add)
.addComponent(multiply).addComponent(equals))
.addGroup(
operLayout.createParallelGroup().addComponent(rightBracket).addComponent(subtract)
.addComponent(divide)));
I understand why this is happening but I'm not sure how to sort it out. Is there a simple way? Or should I change the way I'm doing it? Thanks