Java from getting started to mastering 12-borderlayout layouts

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.