Java Swing SpringLayout singleColumn(final Container container, final int initialY, final int yPad)

Here you can find the source of singleColumn(final Container container, final int initialY, final int yPad)

Description

single Column

License

Apache License

Declaration

public static void singleColumn(final Container container, final int initialY, final int yPad) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.awt.Component;
import java.awt.Container;

import javax.swing.Spring;
import javax.swing.SpringLayout;
import javax.swing.SpringLayout.Constraints;

public class Main {
    public static void singleColumn(final Container container, final int initialY, final int yPad) {
        Spring height = Spring.constant(initialY + yPad * container.getComponentCount());
        Spring width = Spring.constant(0);

        final SpringLayout layout = (SpringLayout) container.getLayout();
        Component previous = container;
        for (final Component component : container.getComponents()) {
            final Constraints constraints = layout.getConstraints(component);
            width = Spring.max(width, constraints.getWidth());
            height = Spring.sum(height, constraints.getHeight());
            if (previous == container) {
                layout.putConstraint(SpringLayout.NORTH, previous, initialY, SpringLayout.NORTH, component);
            } else {
                layout.putConstraint(SpringLayout.SOUTH, previous, yPad, SpringLayout.NORTH, component);
            }//  www. ja  v a  2 s .  c om

            previous = component;
        }

        final Constraints containerConstraints = layout.getConstraints(container);
        containerConstraints.setConstraint(SpringLayout.SOUTH, height);
        containerConstraints.setConstraint(SpringLayout.EAST, width);
    }
}

Related

  1. fixCellWidth(Container parent, int rows, int cols, int initialX, int initialY, int xPad, int yPad, int[] maxX, int[] maxY)
  2. getConstraintsForCell(int row, int col, Container parent, int cols)
  3. makeGrid(final Container parent, final int rows, final int cols, final int initialX, final int initialY, final int xPad, final int yPad)
  4. makeOneLineGrid(Container parent)