Extreme Component

ComponentSet Programmer Guide > Layout Suite

Layout Suite - Java LayoutManager

Layout Suite provides several Java LayoutManager, includes CellLayout, BoxLayout2, GridLayout2, CardLayout2.

CellLayout - Java Form Layout

CellLayout can layout the form like panel better.

Code Samples:

// 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));

BoxLayout2 - Java Button Area Layout

BoxLayout2 is very helpful to layout the button area, layout the component to same width and same height.

Code Samples:

JPanel boxPanel;
boxPanel = new JPanel();
boxPanel.setLayout(new BoxLayout2(boxPanel, BoxLayout.X_AXIS));
boxPanel.setBorder(BorderFactory.createTitledBorder("X_AXIS left align"));	
boxPanel.add(new JButton("ok"));
boxPanel.add(Box.createHorizontalStrut(H_STRUT));
boxPanel.add(new JButton("apply"));
boxPanel.add(Box.createHorizontalStrut(H_STRUT));
boxPanel.add(new JButton("cancel"));
boxPanel.add(Box.createGlue());
panel.add(boxPanel);

GridLayout2 - Java Tool Box Layout

GridLayout2 is very helpful to layout a tool box.

CardLayout2 - Java Card Layout

CardLayout2 provides a card layout.


Copyright (c) zfqjava.com
All rights reserved.