Test Border Layout - Java Swing

Java examples for Swing:BorderLayout

Description

Test Border Layout

Demo Code

import java.awt.BorderLayout;

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

public class Main extends JFrame {

  public Main() {
    super("Border");
    setSize(240, 280);/*from  w  ww. ja va 2 s .  co  m*/
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    setLayout(new BorderLayout());
    JButton nButton = new JButton("North");
    JButton sButton = new JButton("South");
    JButton eButton = new JButton("East");
    JButton wButton = new JButton("West");
    JButton cButton = new JButton("Center");
    add(nButton, BorderLayout.NORTH);
    add(sButton, BorderLayout.SOUTH);
    add(eButton, BorderLayout.EAST);
    add(wButton, BorderLayout.WEST);
    add(cButton, BorderLayout.CENTER);
    setVisible(true);
  }

  public static void main(String[] arguments) {
    Main frame = new Main();
  }
}

Related Tutorials