Setting the Space around a Component Within the Cell of the GridBagLayout Using Insets : GridBagLayout « Swing JFC « Java

Setting the Space around a Component Within the Cell of the GridBagLayout Using Insets

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JButton;
import javax.swing.JFrame;

public class Main {
  public static void main(String[] argv) throws Exception {
    JFrame frame = new JFrame();
    GridBagLayout gbl = new GridBagLayout();

    JButton component = new JButton("1");

    frame.add(new JButton("2"));
    frame.add(new JButton("3"));
    frame.add(new JButton("4"));
    frame.add(new JButton("5"));
    frame.add(new JButton("6"));
    frame.add(new JButton("7"));
    frame.add(new JButton("8"));
    frame.add(new JButton("9"));
    frame.add(new JButton("0"));

    GridBagConstraints gbc = new GridBagConstraints();

    int top = 20;
    int left = 20;
    int bottom = 2;
    int right = 40;
    gbc.insets = new Insets(top, left, bottom, right);

    gbl.setConstraints(component, gbc);



Related examples in the same category

1.GridBagLayout with weightx and weighty constraintsGridBagLayout with weightx and weighty constraints
2.GridBagLayout with constraintsGridBagLayout with constraints
3.Simplest gridbag layoutSimplest gridbag layout
4.GridBagLayout with weight constraintGridBagLayout with weight constraint
5.GridBagLayout with anchor constraintsGridBagLayout with anchor constraints
6.GridBagLayout with gridwidth and gridheight constraintsGridBagLayout with gridwidth and gridheight constraints
7.GridBagLayout PaneGridBagLayout Pane
8.Work with GridBagConstraints 1
9.Work GridBagConstraints 3
10.Work with GridBagConstraints 2
12.Create and set a gridbag layout and how to set gridbag constraints
13.Associate the gridbag constraints with the component
14.Place a component at cell location (1,1)
15.Setting the Location of a Component in a GridBagLayout
16.Making a GridBagLayout Fill the Container
17.Getting the Number of Rows and Columns of Cells in a GridBagLayout
18.Setting the Stretchyness of Rows and Columns in a GridBagLayout Using Layout Weights
19.Place a component at (0,1) with a column weight 1 and a row weight of 2
20.Setting Stretchyness of a GridBagLayout Using Fill
21.Make the component only stretch horizontally
22.Make the component only stretch vertically
23.Make the component on stretchable
24.Make the component stretch in both directions
25.A GridBagLayout Example: weightx, weighty
26.Positioning a component in the center of other component using GridbagLayout
27.Work with GridBagConstraints 5
28.A frame that uses a grid bag layout to arrange font selection components