Example usage for javax.swing Box setPreferredSize

List of usage examples for javax.swing Box setPreferredSize

Introduction

In this page you can find the example usage for javax.swing Box setPreferredSize.

Prototype

@BeanProperty(preferred = true, description = "The preferred size of the component.")
public void setPreferredSize(Dimension preferredSize) 

Source Link

Document

Sets the preferred size of this component.

Usage

From source file:org.jdal.swing.form.SimpleBoxFormBuilder.java

/**
 * Builds the panel form./*from   w ww  . java 2 s  . co m*/
 * @return the form component
 */
public JComponent getForm() {
    // set sizes;
    int columnHeight = 0;
    for (int h : rowsHeight)
        columnHeight += h;

    // add space into components (fillers)
    columnHeight += (rows - 1) * defaultSpace;

    for (int i = 0; i < columns.size(); i++) {
        Box box = columns.get(i);
        int maxWidth = columnsWidth.get(i) == 0 ? Short.MAX_VALUE : columnsWidth.get(i);
        box.setMaximumSize(new Dimension(maxWidth, columnHeight));

        if (maxWidth < Short.MAX_VALUE && columnHeight < Short.MAX_VALUE) {
            box.setMinimumSize(new Dimension(maxWidth, columnHeight));
            box.setPreferredSize(new Dimension(maxWidth, columnHeight));
        }
    }

    container.setFocusTraversalPolicy(focusTransversal);
    container.setFocusTraversalPolicyProvider(true);
    container.setSize(Short.MAX_VALUE, columnHeight);

    if (isFixedHeight()) {
        Dimension maxSize = new Dimension(Short.MAX_VALUE, columnHeight);

        if (container.isMaximumSizeSet()) {
            maxSize = container.getMaximumSize();
            maxSize.height = columnHeight;
        }

        container.setMaximumSize(maxSize);
    }

    if (isDebug())
        container.setBorder(BorderFactory.createLineBorder(Color.BLUE));

    if (border != null)
        container.setBorder(border);

    return container;
}