Gridbag Layout

//<applet code=GridBagLayoutDemo height=400 width=500></applet>
import javax.swing.*;
import java.awt.*;

public class GridBagLayoutDemo extends JApplet {
	JPanel p;
	JButton b1, b2, b3;
	GridBagLayout gl;
	GridBagConstraints gbc;

	@Override
	public void init() {
		p = new JPanel();
		b1 = new JButton("button1");
		b2 = new JButton("button2");
		b3 = new JButton("button3");

		gl = new GridBagLayout();
		gbc = new GridBagConstraints();
		p.setLayout(gl);

		gbc.anchor = GridBagConstraints.NORTHWEST;
		gbc.gridx = 5;
		gbc.gridy = 10;
		gl.setConstraints(b1, gbc);
		p.add(b1);

		gbc.anchor = GridBagConstraints.NORTHWEST;
		gbc.gridx = 20;
		gbc.gridy = 10;
		gl.setConstraints(b2, gbc);
		p.add(b2);

		gbc.anchor = GridBagConstraints.NORTHWEST;
		gbc.gridx = 5;
		gbc.gridy = 15;
		gl.setConstraints(b3, gbc);
		p.add(b3);

		getContentPane().add(p);

	}
}

Download

Layout Manager in Java

Border Layout
Box Layout
Card Layout
Flow Layout
Gridbag Layout
Gridbag Layout
Grid Layout
Design GUI contianer without layout


Write your Comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code