Java Utililty Methods Swing GridLayout

List of utility methods to do Swing GridLayout

Description

The list of methods to do Swing GridLayout are organized into topic(s).

Method

voidgridLayout(JComponent c, int rows, int cols, int gap, boolean n, boolean s, boolean w, boolean e)
grid Layout
SpringLayout sl = new SpringLayout();
c.setLayout(sl);
for (int row = 0; row < rows; row++) {
    if (n) {
        if (row == 0) {
            sl.putConstraint(SpringLayout.NORTH, c.getComponent(0), 0, SpringLayout.NORTH, c);
    if (row != 0) {
        sl.putConstraint(SpringLayout.NORTH, c.getComponent(cols * row), gap, SpringLayout.SOUTH,
                c.getComponent(cols * row - cols));
    if (w) {
        sl.putConstraint(SpringLayout.WEST, c.getComponent(cols * row), 0, SpringLayout.WEST, c);
    for (int col = 1; col < cols; col++) {
        sl.putConstraint(SpringLayout.WEST, c.getComponent(cols * row + col), gap, SpringLayout.EAST,
                c.getComponent(cols * row + col - 1));
        sl.putConstraint(SpringLayout.SOUTH, c.getComponent(cols * row + col), 0, SpringLayout.SOUTH,
                c.getComponent(cols * row + col - 1));
        if (row != 0) {
            sl.putConstraint(SpringLayout.WEST, c.getComponent(cols * row + col), 0, SpringLayout.WEST,
                    c.getComponent(cols * (row - 1) + col));
    if (e) {
        sl.putConstraint(SpringLayout.EAST, c.getComponent(cols * row + cols - 1), 0, SpringLayout.EAST, c);
    if (s) {
        if (row == rows - 1) {
            sl.putConstraint(SpringLayout.SOUTH, c.getComponent(cols * row), 0, SpringLayout.SOUTH, c);
JComponentlayoutEvenHorizontal(JComponent... list)
Layout components in evenly split horizontal boxes
JPanel p = new JPanel(new GridLayout(1, list.length));
for (JComponent c : list)
    p.add(c);
return p;