GridBagLayout is quite different and quite similar to FlowLayout, but with a difference in the position.
new GridBagDemo() : Create the object for the class GridBagDemo
import java.awt.*;GridBagDemo() : Code illustrating GridBagLayout is written here
class GridBagDemo extends Frame
{
Button b1;
Choice c1;
public GridBagDemo()
{
// Set the frame properties
setTitle("GridBagLayout Demo");
setSize(400,400);
setLayout(new GridBagLayout());
setLocationRelativeTo(null);
setVisible(true);
// Create button
b1=new Button(" Buy");
// Create choice
c1=new Choice();
// Add items
c1.add("Apple");
c1.add("Mango");
c1.add("Orange");
c1.add("Guava");
// Add choice
add(c1);
// Add button
add(b1);
}
public static void main(String args[])
{
new GridBagDemo();
}
}
new GridBagDemo() : Create the object for the class GridBagDemo