JFrame BorderLayout Example
This JFrame example shows a content pane containing two labels. It demonstrates the BorderLayout layout manager that the content pane of the JFrame uses by default.
If you dragged a corner of the JFrame to enlarge it, you would see that the layout manager arranges the labels in their appropriate place i.e. at the NORTH and SOUTH positions of the JFrame.
// JFrame BorderLayout Example
import java.awt.*;
import javax.swing.*;
class JFrameBorderLayout {
public static void main(String[] args) {
JFrame jframe = new JFrame("Dairy Products");
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cp = jframe.getContentPane();
cp.add(new JLabel("Sour Cream"),BorderLayout.NORTH);
cp.add(new JLabel("Creme Fraiche"),BorderLayout.SOUTH);
jframe.pack();
jframe.setVisible(true);
}
}
