Java Swing BoxLayout createBox(int axis, Object... children)

Here you can find the source of createBox(int axis, Object... children)

Description

create Box

License

Open Source License

Declaration

private static Box createBox(int axis, Object... children) 

Method Source Code


//package com.java2s;
//it under the terms of the GNU Affero General Public License as published by

import java.awt.Component;

import java.awt.Dimension;

import javax.swing.Box;
import javax.swing.BoxLayout;

public class Main {
    private static Box createBox(int axis, Object... children) {
        if (axis != BoxLayout.X_AXIS && axis != BoxLayout.Y_AXIS)
            throw new IllegalArgumentException();
        boolean horizontal = (axis == BoxLayout.X_AXIS);
        Box box = new Box(axis);
        for (Object child : children) {
            if (child instanceof Component) {
                box.add((Component) child);
            } else if (child instanceof Dimension) {
                box.add(Box.createRigidArea((Dimension) child));
            } else if (child == null) {
                box.add(horizontal ? Box.createHorizontalGlue() : Box.createVerticalGlue());
            } else if (child instanceof Integer) {
                int strut = (Integer) child;
                box.add(horizontal ? Box.createHorizontalStrut(strut) : Box.createVerticalStrut(strut));
            } else {
                throw new ClassCastException(
                        "Child must be component or invisible box specification (strut=integer, rigid area=dimension, glue=null)");
            }/*from  w  w  w. j  a  v  a 2 s.  com*/
        }
        return box;
    }
}

Related

  1. applyVerticalBoxLayout(Container p)
  2. combineInNorth(JComponent[] components)
  3. createBox(Component center, Component north, Component south, Component west, Component east)
  4. createBox(int orientation, JComponent... components)
  5. createBoxFiller()
  6. createBoxLayout(Container container, int axis, Component... components)
  7. createBoxLayoutPanel(boolean vertical)