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

public static void setUpMenuEntries(JMenuItem item) {
    item.setMargin(new Insets(5, 20, 50, 20));
    item.setFont(new Font(APP_FONT, Font.PLAIN, 20));
}

From source file:Main.java

public static void setMargin(final JComponent component, final int eachSide) {
    final Insets insets = new Insets(eachSide, eachSide, eachSide, eachSide);
    setMargin(component, insets);/*from   w  ww .  j  a  va  2  s  .co m*/
}

From source file:Main.java

public static JPanel createVertical(final Component... components) {
    final JPanel jp = new JPanel(new GridBagLayout());
    final GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;//from   w w  w .j  a va 2  s . c  o m
    gbc.gridy = 0;
    gbc.insets = new Insets(0, 5, 4, 5);
    gbc.anchor = GridBagConstraints.NORTH;
    gbc.weightx = 1.0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    for (final Component component : components) {
        if (gbc.gridy == components.length - 1) {
            gbc.weighty = 1.0;
        }
        jp.add(component, gbc);
        gbc.gridy++;
    }
    return jp;
}

From source file:Main.java

/**
 * @param label/*w w w . j  a  v  a 2  s.  c  o  m*/
 * @param iconFileName
 * @return createb JButton used in toolbar
 */
public static JButton createToolbarButton(String label, String iconFileName) {
    JButton button = new JButton(new ImageIcon(iconFileName));
    button.setFocusPainted(false);
    button.setMargin(new Insets(0, 0, 0, 0));
    button.setToolTipText(label);
    button.setActionCommand(label);
    return button;
}

From source file:Main.java

public static Rectangle getTextRectangle(JLabel label) {

    String text = label.getText();
    Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();

    if ((icon == null) && (text == null)) {
        return null;
    }/*from  w w w .  ja va2  s  .c o  m*/

    Rectangle paintIconR = new Rectangle();
    Rectangle paintTextR = new Rectangle();
    Rectangle paintViewR = new Rectangle();
    Insets paintViewInsets = new Insets(0, 0, 0, 0);

    paintViewInsets = label.getInsets(paintViewInsets);
    paintViewR.x = paintViewInsets.left;
    paintViewR.y = paintViewInsets.top;
    paintViewR.width = label.getWidth() - (paintViewInsets.left + paintViewInsets.right);
    paintViewR.height = label.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);

    Graphics g = label.getGraphics();
    if (g == null) {
        return null;
    }
    String clippedText = SwingUtilities.layoutCompoundLabel(label, g.getFontMetrics(), text, icon,
            label.getVerticalAlignment(), label.getHorizontalAlignment(), label.getVerticalTextPosition(),
            label.getHorizontalTextPosition(), paintViewR, paintIconR, paintTextR, label.getIconTextGap());

    return paintTextR;
}

From source file:Main.java

/**
 * Configures a button as if it was an hyperlink.
 * //from w  ww.j a va2 s. c o  m
 * @param button
 *            the button to configure.
 */
public static void configureButtonAsHyperlink(JButton button) {
    if (button == null) {
        return;
    }

    StringBuffer html = new StringBuffer();
    html.append("<html><font color=\"blue\"><u>");
    html.append(button.getText());
    html.append("</u></font></html>");

    button.setText(html.toString());
    button.setMargin(new Insets(0, 0, 0, 0));
    button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    button.setFocusPainted(false);
    button.setBorderPainted(false);
    button.setContentAreaFilled(false);
}

From source file:Main.java

public static GridBagConstraints createConstraints(int gridx, int gridy, int gridwidth, int gridheight) {
    return createConstraints(gridx, gridy, gridwidth, gridheight, GridBagConstraints.WEST,
            GridBagConstraints.NONE, new Insets(5, 0, 0, 0));
}

From source file:Main.java

/**
 * @param label/*from   w  w  w.j av  a 2s  . co  m*/
 * @param icon
 * @return createb JButton used in toolbar
 */
public static JButton createToolbarButton(String label, Icon icon) {
    JButton button = new JButton(icon);
    button.setFocusPainted(false);
    button.setMargin(new Insets(0, 0, 0, 0));
    button.setToolTipText(label);
    button.setActionCommand(label);
    return button;
}

From source file:Main.java

public static void addComponent(final Container cont, final GridBagLayout gbl, final Component c, final int x,
        final int y, final int width, final int height, final double weightx, final double weighty,
        final int anchor, final int fill) {
    addComponent(cont, gbl, c, x, y, width, height, weightx, weighty, anchor, fill, new Insets(0, 0, 0, 0));
}

From source file:Main.java

public static Point arrangeWithin(final Shape shapeToArrange, final Rectangle window, final int arrangement,
        final int padding) {
    return arrangeWithin(shapeToArrange, window, arrangement, new Insets(padding, padding, padding, padding));
}