// create a CellLayout with 7 rows, 5 columns, and default horizontal gap is 6 point and default vertical gap is 5 point
CellLayout cellLayout = new CellLayout(7, 5, 6, 5);
// sets the the second column weight to 1.0
cellLayout.setColumnWeight(1, 1.0);
// add the component with a CellLayout.Constraints
JPanel panel = new JPanel(cellLayout);
for(int i=0; i<6; i++) {
JLabel label = new JLabel("hello"+i);
panel.add(label, new CellLayout.Constraints(0, i));
}
for(int i=0; i<6; i++) {
JTextField field = new JTextField("world"+i, 9);
field.setAlignmentX(0.0f);
panel.add(field, new CellLayout.Constraints(1, i));
}
JLabel label = new JLabel("hello6");
label.setAlignmentY(0.0f);
panel.add(label, new CellLayout.Constraints(0, 6));
JScrollPane scrollPane = new JScrollPane(new JList());
scrollPane.setAlignmentX(0.0f);
panel.add(scrollPane, new CellLayout.Constraints(1, 6));
|