I need to create a GUI using GroupLayout (not other layouts). The graphical interface will look like this:
----------------------------
| field 1 field 2 field 3 |
| FFIEEELLLDD4 FIELDDDDDD5 |
| FIEEEEEEEEEEEEEEELDDDD 6 |
_____________________________
Fields 1-3 take 1 length, fields 4 and 5 take 1.5 lengths, and field 6 takes 3 lengths. Three groups are aligned both at the beginning and at the end.
I meant this http://docs.oracle.com/javase/tutorial/uiswing/layout/group.html .
For simplicity, I will use JLabels as field place holders.
Here is my code so far, and I was not lucky to get the GUI that I wanted.
public class RecorderGUI extends JFrame {
private final JLabel one;
private final JLabel two;
private final JLabel three;
private final JLabel four;
private final JLabel five;
private final JLabel six;
public RecorderGUI() {
JFrame frame = new JFrame();
JPanel panel = new JPanel();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GroupLayout layout = new GroupLayout(panel);
panel.setLayout(layout);
one = new JLabel("one");
two = new JLabel("two");
three = new JLabel("three");
four = new JLabel("four");
five = new JLabel("five");
six = new JLabel("six");
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup())
.addComponent(one)
.addComponent(two)
.addComponent(three)
.addGroup(layout.createSequentialGroup())
.addComponent(four)
.addComponent(five))
.addComponent(six));
layout.setVerticalGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(one)
.addComponent(two)
.addComponent(three))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(four)
.addComponent(five))
.addComponent(six));
frame.add(panel);
frame.pack();
frame.setVisible(true);
}
public static void main(final String[] args) {
RecorderGUI GUI = new RecorderGUI();
}
As a result of the code, the following appears, which I did not want: one, two and three are combined together; four and five overlap.
, , , 10 : (.