BorderLayout
Java Swing Tutorial Explaining the BorderLayout . BorderLayout places swing components in the North, South, East, West and center of a container. All extra space is placed in the center area. You can add horizontal and vertical gaps between the areas.
Every content pane is initialized to use a BorderLayout. Components are added to a BorderLayout by using the add method. JFrame’s content pane default layout manager: BorderLayout. In BorderLayout, a component’s position is specified by a second argument to add.
BorderLayout Source Code
/* * BorderLayoutDemo.java is a 1.4 application that requires no other files. */ import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; public class BorderLayoutDemo { public static boolean RIGHT_TO_LEFT = false; public static void addComponentsToPane(Container contentPane) { // Use BorderLayout. Default empty constructor with no horizontal and vertical // gaps contentPane.setLayout(new BorderLayout(5,5)); if (!(contentPane.getLayout() instanceof BorderLayout)) { contentPane.add(new JLabel("Container doesn't use BorderLayout!")); return; } if (RIGHT_TO_LEFT) { |
output
Download BorderLayout Source Code
0 comments:
Post a Comment