The Boundary layout manager divides the layout of a container into five locations: CENTER, EAST, WEST, North, south. This corresponds to the following: North, Lower South, Levocetirizine (WEST), right East (east), Middle (CENTER), as shown in.
Characteristics:
L can place the component in any of these five positions, if no position is specified, the default position is center.
L South and North position controls occupy one row, and the width of the control is automatically filled with the entire row. The east, west, and middle positions occupy one row; if there is no control in the eastern, Western, south, and North locations, the intermediate controls will automatically fill the entire screen. In Jaudon, West, south, and North locations where there is no control, the middle position control automatically occupies the position without the control.
Building functions and methods
Construction Method Summary |
BorderLayout (): Constructs a new border layout with no spacing between components (the default spacing is 0 pixels). |
|
BorderLayout (int hgap, int vgap): Constructs a border layout with the specified component (Hgap for horizontal spacing, vgap for vertical spacing). |
|
Method Summary |
Int |
Gethgap (): Returns the horizontal spacing between components. |
Int |
Getvgap (): Returns the vertical spacing between components. |
void |
Removelayoutcomponent (Component comp): Removes the specified component from this border layout. |
void |
Sethgap (int hgap): Sets the horizontal spacing between components. |
void |
Setvgap (int vgap): Sets the vertical spacing between components. |
Borderlay Layout Instance Code
Import javax.swing.*; import java.awt.*;/** * Created by Andrew on 2015/10/14. * BorderLayout Demo*/ Public classBorderdemo extends JFrame {//define the required swing components hereJButton Btneast,btnwest,btnnorth,btnsouth,btnmiddle; Public Static voidMain (String args[]) {Borderdemo Borderdemo=NewBorderdemo (); } //constructor Function PublicBorderdemo () {//Creating and adding componentsbtneast=NewJButton ("East"); Btnwest=NewJButton ("Western"); Btnnorth=NewJButton ("North"); Btnsouth=NewJButton ("South"); Btnmiddle=NewJButton ("Chubu"); This. Add (Btneast, borderlayout.east); This. Add (Btnwest,borderlayout.west); This. Add (Btnnorth,borderlayout.north); This. Add (Btnsouth,borderlayout.south); This. Add (Btnmiddle,borderlayout.center); //Setting Parameters This. Settitle (the boundary layout case"); This. SetSize (1024x768,768); This. Setlocationrelativeto (NULL); This. Setdefaultcloseoperation (Jframe.exit_on_close); This. setvisible (true); }}
Java from getting started to mastering 12-borderlayout layouts