AWT graphic user interface design II (layout manager 1)

Source: Internet
Author: User

2. borderlayout

Borderlayout is the default layout manager for Windows, frames, and dialog. The borderlayout layout manager divides containers into five areas: north, south, east, west, and center. Only one component can be placed in each area. Shows the location and size of each region:

    

Example 5.5
Import java. AWT .*;
Public class buttondir {
Public static void main (string ARGs []) {
Frame F = new frame ("borderlayout ");
F. setlayout (New borderlayout ());
F. Add ("North", new button ("North "));
// The first parameter indicates adding the button to the North area of the container
F. Add ("South", new button ("South "));
// The first parameter indicates adding the button to the south area of the container
F. Add ("East", new button ("East "));
// The first parameter indicates adding the button to the East region of the container
F. Add ("West", new button ("West "));
// The first parameter indicates adding the button to the west area of the container
F. Add ("center", new button ("center "));
// The first parameter indicates adding the button to the center area of the container
F. setsize (200,200 );
F. setvisible (true );
}
}

When borderlayout is used, if the container size changes, the variation rule is: the relative position of the component remains unchanged, and the size changes. For example, if the container is higher, the North and South regions remain unchanged, and the west, center, and east regions become higher. If the container is wider, the west and east regions remain unchanged, and the north, center, and South regions become wider. Not all regions have components. If there are no components in the surrounding areas (west, east, north, and South), the components are added in the center area. However, if there are no components in the center area, leave it blank, as shown in the following figure:

  
Components missing in the North Region

  
Components are missing in the north and center regions.

3. gridlayout

Each component in the container is displayed in a grid layout, occupying the container space on average.

Example 5.6
Import java. AWT .*;
Public class buttongrid {
Public static void main (string ARGs []) {
Frame F = new frame ("gridlayout ");
F. setlayout (New gridlayout (3, 2 ));
// Containers are evenly divided into three rows, two columns, and six cells in total.
F. Add (New button ("1"); // Add it to the first row
F. Add (New button ("2"); // Add to the next grid of the first row
F. Add (New button ("3"); // Add it to the first row of the second row
F. Add (New button ("4"); // Add it to the next cell of the second row
F. Add (New button ("5"); // Add the first row to the third row
F. Add (New button ("6"); // Add it to the next grid of the third row
F. setsize (200,200 );
F. setvisible (true );
}
}

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.