GridBagLayoutGridHeight.java Source code

Java tutorial

Introduction

Here is the source code for GridBagLayoutGridHeight.java

Source

import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

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

public class GridBagLayoutGridHeight {

    public static void main(String[] args) {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container pane = f.getContentPane();
        pane.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        pane.add(new JLabel("First row, first column"), gbc);
        pane.add(new JLabel("First row, second column"), gbc);
        gbc.gridheight = GridBagConstraints.REMAINDER;
        gbc.fill = GridBagConstraints.VERTICAL;
        pane.add(new JLabel("First row, third column"), gbc);
        gbc.gridx = 0;
        gbc.gridheight = 1;
        gbc.fill = GridBagConstraints.NONE;
        pane.add(new JButton("Second row"), gbc);
        pane.add(new JButton("Third row"), gbc);
        f.setSize(600, 300);
        f.setVisible(true);
    }

}