Example usage for java.awt GridBagLayout GridBagLayout

List of usage examples for java.awt GridBagLayout GridBagLayout

Introduction

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

Prototype

public GridBagLayout() 

Source Link

Document

Creates a grid bag layout manager.

Usage

From source file:Main.java

public Main() {
    getContentPane().setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    JPanel panel1 = new JPanel();
    Border eBorder = BorderFactory.createEtchedBorder();
    panel1.setBorder(BorderFactory.createTitledBorder(eBorder, "70pct"));
    gbc.gridx = gbc.gridy = 0;// w w w.  j  a  va2 s  .c  o m
    gbc.gridwidth = gbc.gridheight = 1;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.weightx = gbc.weighty = 70;
    getContentPane().add(panel1, gbc);
    JPanel panel2 = new JPanel();
    panel2.setBorder(BorderFactory.createTitledBorder(eBorder, "30pct"));
    gbc.gridy = 1;
    gbc.weightx = 30;
    gbc.weighty = 30;
    gbc.insets = new Insets(2, 2, 2, 2);
    getContentPane().add(panel2, gbc);
    pack();
}

From source file:Main.java

Main() {

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(500, 500);/* www.ja  v a2  s  . c  om*/

    JPanel panel1 = new JPanel(new GridBagLayout());
    JButton b1 = new JButton("button 1"), b2 = new JButton("button 2");
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridwidth = 1;
    panel1.add(b1, gbc);
    gbc.gridx = 2;
    gbc.gridwidth = 2;
    gbc.fill = gbc.HORIZONTAL; // set fill property to HORIZONTAL
    gbc.weightx = 2.0;
    panel1.add(b2, gbc); // While adding button also add it with gbc
    add(panel1);
    setVisible(true);
}

From source file:Main.java

public Main() {
    setLayout(new GridBagLayout());
    constraints.weightx = 1.0;/*  w  w  w. j  av a 2s .co m*/
    constraints.weighty = 1.0;
    constraints.fill = GridBagConstraints.BOTH;
    int x, y; // for clarity
    addGB(new JButton("North"), x = 1, y = 0);
    addGB(new JButton("West"), x = 0, y = 1);
    addGB(new JButton("Center"), x = 1, y = 1);
    addGB(new JButton("East"), x = 2, y = 1);
    addGB(new JButton("South"), x = 1, y = 2);
}

From source file:GridBag1.java

public GridBag1() {
    setLayout(new GridBagLayout());
    int x, y; // for clarity
    addGB(new JButton("North"), x = 1, y = 0);
    addGB(new JButton("West"), x = 0, y = 1);
    addGB(new JButton("Center"), x = 1, y = 1);
    addGB(new JButton("East"), x = 2, y = 1);
    addGB(new JButton("South"), x = 1, y = 2);
}

From source file:Main.java

public Main() {
    setLayout(new GridBagLayout());
    int x, y; // for clarity
    addGB(new JButton("North"), x = 1, y = 0);
    constraints.ipadx = 25; // add padding
    constraints.ipady = 25;/*from ww  w  .j  av a2 s.  c  om*/
    addGB(new JButton("West"), x = 0, y = 1);
    constraints.ipadx = 0; // remove padding
    constraints.ipady = 0;
    addGB(new JButton("Center"), x = 1, y = 1);
    addGB(new JButton("East"), x = 2, y = 1);
    addGB(new JButton("South"), x = 1, y = 2);
}

From source file:Main.java

public Main() {
    setLayout(new GridBagLayout());
    constraints.weightx = 1.0;//w w  w  .j  a  va2s.com
    constraints.weighty = 1.0;
    constraints.fill = GridBagConstraints.BOTH;
    int x, y;
    constraints.gridheight = 2; // span two rows
    addGB(new JButton("one"), x = 0, y = 0);
    constraints.gridheight = 1; // set it back
    addGB(new JButton("two"), x = 1, y = 0);
    addGB(new JButton("three"), x = 2, y = 0);
    constraints.gridwidth = 2; // span two columns
    addGB(new JButton("four"), x = 1, y = 1);
    constraints.gridwidth = 1; // set it back
}

From source file:GridBag2.java

public GridBag2() {
    setLayout(new GridBagLayout());
    constraints.weightx = 1.0;// w ww  .j av  a2  s. co  m
    constraints.weighty = 1.0;
    constraints.fill = GridBagConstraints.BOTH;
    int x, y; // for clarity
    addGB(new JButton("North"), x = 1, y = 0);
    addGB(new JButton("West"), x = 0, y = 1);
    addGB(new JButton("Center"), x = 1, y = 1);
    addGB(new JButton("East"), x = 2, y = 1);
    addGB(new JButton("South"), x = 1, y = 2);
}

From source file:GridBag4.java

public GridBag4() {
    setLayout(new GridBagLayout());
    constraints.fill = GridBagConstraints.BOTH;
    constraints.weighty = 1.0;/*  ww w.j  a  va2  s .  c o  m*/
    int x, y; // for clarity
    constraints.weightx = 0.1;
    addGB(new JButton("one"), x = 0, y = 0);
    constraints.weightx = 0.5;
    addGB(new JButton("two"), ++x, y);
    constraints.weightx = 1.0;
    addGB(new JButton("three"), ++x, y);
}

From source file:Main.java

public Main() {
    setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    JPanel panel1 = new JPanel();
    Border eBorder = BorderFactory.createEtchedBorder();

    panel1.setBorder(BorderFactory.createTitledBorder(eBorder, "70pct"));
    gbc.gridx = gbc.gridy = 0;//from  w w  w . j  ava2s. com
    gbc.gridwidth = gbc.gridheight = 1;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.weightx = gbc.weighty = 70;
    add(panel1, gbc);

    JPanel panel2 = new JPanel();
    panel2.setBorder(BorderFactory.createTitledBorder(eBorder, "30pct"));
    gbc.gridy = 1;
    gbc.weightx = gbc.weighty = 30;
    gbc.insets = new Insets(2, 2, 2, 2);
    add(panel2, gbc);

    JPanel panel3 = new JPanel();
    panel3.setBorder(BorderFactory.createTitledBorder(eBorder, "20pct"));
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.gridwidth = 1;
    gbc.gridheight = 2;
    gbc.weightx = 20;
    gbc.insets = new Insets(2, 2, 2, 2);
    add(panel3, gbc);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
    setVisible(true);
}

From source file:MainClass.java

public MainClass() {
    setLayout(new GridBagLayout());
    constraints.weightx = 1.0;//  ww  w  . j a v a 2 s.c  om
    constraints.weighty = 1.0;
    constraints.fill = GridBagConstraints.BOTH;
    int x, y; // for clarity
    addGB(new JButton("North"), x = 1, y = 0);
    addGB(new JButton("West"), x = 0, y = 1);
    addGB(new JButton("Center"), x = 1, y = 1);
    addGB(new JButton("East"), x = 2, y = 1);
    addGB(new JButton("South"), x = 1, y = 2);
}