A Simple Java Program demonstrating a way to use BorderLayout layout using Swing API.
Output of the program :
package com.hubberspot.swing.example;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class BorderLayoutDemo extends JFrame {
public BorderLayoutDemo() {
add(BorderLayout.NORTH, new JButton("North"));
add(BorderLayout.SOUTH, new JButton("South"));
add(BorderLayout.EAST, new JButton("East"));
add(BorderLayout.WEST, new JButton("West"));
add(BorderLayout.CENTER, new JButton("Center"));
}
public static void main(String[] args) {
setFrame(new BorderLayoutDemo(), 300, 200);
}
public static void
setFrame(final JFrame frame, final int width, final int height) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
frame.setTitle(frame.getClass().getSimpleName());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(width, height);
frame.setVisible(true);
}
});
}
}
Output of the program :
