Example usage for java.awt Insets Insets

List of usage examples for java.awt Insets Insets

Introduction

In this page you can find the example usage for java.awt Insets Insets.

Prototype

public Insets(int top, int left, int bottom, int right) 

Source Link

Document

Creates and initializes a new Insets object with the specified top, left, bottom, and right insets.

Usage

From source file:Main.java

/**
 * Returns insets converted into RTL orientation.
 *
 * @param insets// w ww.jav a  2s  .co  m
 *            insets to convert
 * @return insets converted into RTL orientation
 */
public static Insets toRTL(final Insets insets) {
    return new Insets(insets.top, insets.right, insets.bottom, insets.left);
}

From source file:Main.java

/**
 * Returns minimum insets combined from the specified ones.
 *
 * @param insets1 first insets//  w w  w  .  ja v  a  2  s .c  o m
 * @param insets2 second insets
 * @return minimum insets
 */
public static Insets min(final Insets insets1, final Insets insets2) {
    if (insets1 != null && insets2 != null) {
        return new Insets(Math.min(insets1.top, insets2.top), Math.min(insets1.left, insets2.left),
                Math.min(insets1.bottom, insets2.bottom), Math.min(insets1.right, insets2.right));
    } else if (insets1 != null) {
        return insets1;
    } else if (insets2 != null) {
        return insets2;
    } else {
        return null;
    }
}

From source file:Main.java

public static void addComponentToGridBagLayout(Container cont, GridBagLayout gbl, int x, int y, int width,
        int height, double weightx, double weighty, Component component) {
    GridBagConstraints gbc = new GridBagConstraints();

    if (y == 0)/* w  w  w.j  a  v  a  2  s. c om*/
        gbc.insets = new Insets(8, 6, 4, 6);
    else
        gbc.insets = new Insets(4, 6, 4, 6);

    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = x;
    gbc.gridy = y;
    gbc.gridwidth = width;
    gbc.gridheight = height;
    gbc.weightx = weightx;
    gbc.weighty = weighty;
    gbl.setConstraints(component, gbc);
    cont.add(component);
}

From source file:Main.java

private static void addComponent(Container container, Component component, int gridx, int gridy, int gridwidth,
        int gridheight, int anchor, int fill) {
    Insets insets = new Insets(0, 0, 0, 0);
    GridBagConstraints gbc = new GridBagConstraints(gridx, gridy, gridwidth, gridheight, 1.0, 1.0, anchor, fill,
            insets, 0, 0);//from   w w  w . jav  a 2s . com
    container.add(component, gbc);
}

From source file:Main.java

/**
 * Lays out a list of controls in a compact grid-layout, meaning that each
 * cell in the grid only takes up it's preferred size.
 * /*from  ww w  . j a va2s . c o m*/
 * @param parent the parent <code>Container</code>
 * @param colCount the number of columns
 * @param padding the number of pixels to pad between cells
 * @param components a <code>List</code> of <code>Component</code>s that
 *        should be added to <code>parent</code>
 */
public static void makeCompactGrid(Container parent, int colCount, int padding,
        List<? extends Component> components) {

    parent.setLayout(new GridBagLayout());

    final int componentCount = components.size();
    final int rowCount = getRowCount(componentCount, colCount);

    final GridBagConstraints c = new GridBagConstraints();
    final int realPadding = (padding / 2);

    c.gridheight = 1;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1;
    c.weighty = 1;
    c.insets = new Insets(realPadding, realPadding, realPadding, realPadding);

    for (int i = 0; i < (rowCount * colCount); i++) {
        final int x = (i % colCount);
        final int y = (i / colCount);

        c.gridx = x;
        c.gridy = y;

        parent.add(components.get(i), c);
    }
}

From source file:Main.java

public static JToggleButton createToggleButton(ImageIcon icon, int dimension, String tooltipText) {
    JToggleButton btn = new JToggleButton();
    btn.setToolTipText(tooltipText);//from  w w  w .  ja v a 2s. co m
    btn.setIcon(icon);

    btn.setMaximumSize(new Dimension(dimension, dimension));
    btn.setMinimumSize(new Dimension(dimension, dimension));
    btn.setPreferredSize(new Dimension(dimension, dimension));
    btn.setMargin(new Insets(0, 0, 0, 0));

    return btn;
}

From source file:RectangleBorder.java

public RectangleBorder(Color color) {
    this(color, new Insets(1, 1, 1, 1));
}

From source file:Main.java

public static JPanel createKV(final Component key, final Component value, final int keyWidth,
        final boolean fill) {
    initComponentHeight(key, value);//from   w  w  w .j a  v  a2 s  .c  om
    if (keyWidth > 0) {
        key.setPreferredSize(new Dimension(keyWidth, key.getPreferredSize().height));
    }
    final JPanel jp = new JPanel(new GridBagLayout());
    final GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.WEST;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.insets = new Insets(0, 0, 0, 4);
    jp.add(key, gbc);
    gbc.gridx = 1;
    gbc.insets = new Insets(0, 0, 0, 0);
    gbc.weightx = 1.0;
    if (fill) {
        gbc.fill = GridBagConstraints.HORIZONTAL;
    }
    jp.add(value, gbc);
    return jp;
}

From source file:Main.java

Main() {

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(500, 500);/*from  w  ww.ja  v a2 s  . com*/

    JPanel panel1 = new JPanel(new GridBagLayout());
    JButton b1 = new JButton("button 1"), b2 = new JButton("button 2");

    panel1.add(b1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    panel1.add(b2, new GridBagConstraints(1, 0, 1, 1, 2.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    add(panel1);
    setVisible(true);
}

From source file:RedGreenBorder.java

public Insets getBorderInsets(Component c) {
    return new Insets(3, 3, 3, 3);
}