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 Point arrangeWithin(final Shape shapeToArrange, final Rectangle window, final int arrangement,
        Insets padding) {/*from  w  w  w  . jav a  2s  .com*/
    if (shapeToArrange == null)
        throw new IllegalArgumentException("Parameter 'shapeToArrange' must not be null!");
    if (window == null)
        throw new IllegalArgumentException("Parameter 'window' must not be null!");
    if (padding == null)
        padding = new Insets(0, 0, 0, 0);

    final Rectangle bounds = shapeToArrange.getBounds();

    switch (arrangement) {
    case SwingConstants.NORTH:
        return new Point((window.width - bounds.width) / 2, padding.top);
    case SwingConstants.NORTH_EAST:
        return new Point(window.width - padding.right, padding.top);
    case SwingConstants.EAST:
        return new Point(window.width - padding.right, (window.height - bounds.height) / 2);
    case SwingConstants.SOUTH_EAST:
        return new Point(window.width - padding.right, window.height - padding.bottom);
    case SwingConstants.SOUTH:
        return new Point((window.width - bounds.width) / 2, window.height - padding.bottom);
    case SwingConstants.SOUTH_WEST:
        return new Point(padding.left, window.height - padding.bottom);
    case SwingConstants.WEST:
        return new Point(padding.left, (window.height - bounds.height) / 2);
    case SwingConstants.NORTH_WEST:
        return new Point(padding.left, padding.top);
    case SwingConstants.CENTER:
        return new Point((window.width - bounds.width) / 2, (window.height - bounds.height) / 2);
    default:
        throw new IllegalArgumentException("Illegal arrangement key, expected one of the SwingConstants keys");
    }
}

From source file:Main.java

public Main() {
    setPreferredSize(new Dimension(500, 500));
    getContentPane().setLayout(new BorderLayout());
    JPanel panel = new JPanel(new GridBagLayout());

    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(4, 4, 4, 4);
    panel.add(new JLabel("Label"), c);

    panel.add(new JTextField(20), c);

    c.gridwidth = GridBagConstraints.REMAINDER;
    panel.add(new JButton("btn"), c);
    c.gridwidth = 1;/*from  w w w.  ja  va 2s  .co  m*/

    panel.add(new JLabel("Name"), c);

    panel.add(new JTextField(20), c);

    c.gridwidth = GridBagConstraints.REMAINDER;
    panel.add(new JButton("btn"), c);
    c.weighty = 1.0;
    panel.add(Box.createGlue(), c);

    add(panel, BorderLayout.LINE_START);

    pack();
    setVisible(true);
}

From source file:Main.java

public Main() {
    GridBagLayout layout = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    getContentPane().setLayout(layout);// w  w w . j  a  va 2 s  .co m
    constraints.anchor = GridBagConstraints.WEST;
    JLabel l1 = new JLabel("First Name:");
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.BOTH;
    constraints.insets = new Insets(5, 5, 5, 5);
    layout.setConstraints(l1, constraints);
    getContentPane().add(l1);

    JTextField t1 = new JTextField();
    constraints.gridx = 1;
    constraints.gridy = 0;
    constraints.weightx = 1;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.insets = new Insets(5, 5, 5, 5);
    layout.setConstraints(t1, constraints);
    getContentPane().add(t1);

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(700, 500);
}

From source file:Main.java

public JComponent makeUI() {
    UIManager.put("TabbedPane.tabInsets", new Insets(2, 2, 2, 50));
    final JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab("A", new JPanel());

    JPanel p = new JPanel(new BorderLayout());
    p.add(new JLayer<JTabbedPane>(tabbedPane, new CloseableTabbedPaneLayerUI()));
    p.add(new JButton(new AbstractAction("add tab") {
        @Override/*  ww  w  .j a  v a 2  s . c o m*/
        public void actionPerformed(ActionEvent e) {
            tabbedPane.addTab("test", new JPanel());
        }
    }), BorderLayout.SOUTH);
    return p;
}

From source file:OvalBorder.java

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

From source file:Main.java

/**
 * Returns insets copy.//from w w w  . j a  v a2 s.co  m
 *
 * @param insets
 *            insets to copy
 * @return insets copy
 */
public static Insets copy(final Insets insets) {
    return new Insets(insets.top, insets.left, insets.bottom, insets.right);
}

From source file:Main.java

/**
 * @param panel//from  ww w  . j a  v  a 2 s  .  c  o m
 * @return pre-configured constraints
 */
public static GridBagConstraints initPanel(JPanel panel) {
    panel.setLayout(new GridBagLayout());
    panel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    GridBagConstraints gb = new GridBagConstraints();
    gb.gridx = 0;
    gb.gridy = 0;
    gb.insets = new Insets(2, 2, 2, 2);
    return gb;
}

From source file:Main.java

/**
 * Returns maximum insets combined from the specified ones.
 *
 * @param insets1 first insets/*from w  ww  .j  a v  a2s  . co  m*/
 * @param insets2 second insets
 * @return maximum insets
 */
public static Insets max(final Insets insets1, final Insets insets2) {
    if (insets1 != null && insets2 != null) {
        return new Insets(Math.max(insets1.top, insets2.top), Math.max(insets1.left, insets2.left),
                Math.max(insets1.bottom, insets2.bottom), Math.max(insets1.right, insets2.right));
    } else if (insets1 != null) {
        return insets1;
    } else if (insets2 != null) {
        return insets2;
    } else {
        return null;
    }
}

From source file:Main.java

/**
 * @param scrollPane/*from  w  ww.  j  av  a  2s . c  o  m*/
 * @return
 */
public static GridBagConstraints initScrollPane(JScrollPane scrollPane) {
    scrollPane.setLayout(new ScrollPaneLayout());
    scrollPane.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    GridBagConstraints gb = new GridBagConstraints();
    gb.gridx = 0;
    gb.gridy = 0;
    gb.insets = new Insets(2, 2, 2, 2);
    return gb;
}

From source file:Main.java

public Main() {
    super(BoxLayout.Y_AXIS);
    try {/* ww w  . jav  a2  s.  c  o m*/
        for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                UIManager.setLookAndFeel(info.getClassName());
                System.out.println("set");
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    Object o = UIManager.get("TextArea[Enabled+NotInScrollPane].borderPainter");

    UIDefaults paneDefaults = new UIDefaults();
    paneDefaults.put("TextPane.borderPainter", o);

    JTextPane pane = new JTextPane();
    pane.setMargin(new Insets(10, 10, 10, 10));

    pane.putClientProperty("Nimbus.Overrides", paneDefaults);
    pane.putClientProperty("Nimbus.Overrides.InheritDefaults", false);
    pane.setText("this \nis \na \ntest\n");
    add(pane);

}