Java GUI layout manager

Source: Internet
Author: User

1. flowlayout: Flow layout manager, which is the default layout manager for panel-type containers.
Layout effect: the component is positioned row by row in the order of adding in the container. The line is left to right, and the line is full before the line is wrapped. The default alignment mode is center alignment.
Common constructor methods:
Public flowlayout (): Default
Public flowlayout (INT align): Creates flowlayout and sets the alignment mode.
Public flowlayout (INT align, int hgap, int vagp): Creates flowlayout and sets the alignment mode, vertical and horizontal spacing of components.
Flowlayout. Left left alignment
Flowlayout. Right
Flowlayout. Center center alignment

 

2. borderlayout border layout manager is the default layout manager for Windows and sub-classes (frame, DIALOG.
Component layout effect: divide the entire container into five parts: east, west, south, north, and middle (east, west, south, north, center, a widget can only be added to a specified region. By default, only one widget can be added to each region. Vertical Scaling in the East and West, horizontal scaling in the South and North.
Constructor:
Public borderlayout (): Creates the default layout manager.
Public borderlayout (int h, int V): Specifies the horizontal and vertical spacing.
Use five constants to represent five regions
Borderlayout. East
Borderlayout. West
Borderlayout. North
Borderlayout. South
Borderlayout. Center
For example, F. Add (button, "sourth") = f. Add (button, borderlayout. sourth), but the second method is relatively better.

 

3. gridlayout grid layout.
Layout effect: divide the container into a regular rectangular grid with the same size of each cell.
Public gridlayout (); by default, all components occupy one column in the same row.
Public gridlayout (INT rows, int Cols): specifies the number of rows and columns.
Public gridlayout (INT rows, int cols, int H, int V): specifies the number of rows, columns and verticals, and horizontal spacing.

 

4. cardlayout: Card Layout
Layout effect: multiple components are displayed alternately in the same container area, which is equivalent to multiple cards stacked together and only visible at the top.
Common Methods:
Public void first (contains Paren) is flipped to the first card of the specified container.
Public void last (contains Paren) is flipped to the last card of the specified container.
Public void previous (contains Paren) is flipped to the previous card of the specified container.
Public void next (contains Paren) is flipped to the next card of the specified container.
Public void show (contains Paren, string name) is flipped over to the component with the specified name added to this layout. If it does not exist, no operation will take place.

 

5. boxlayout layout manager: The boxlayout layout allows controls to be placed in the X axis (from left to right) or Y axis (from top to bottom) direction, and different dimensions can be set along the main axis.

 

6. gridbaglayout layout manager:

Developed based on gridlayout. Because each grid in gridbaglayout is of the same size and the force component is of the same size as the grid, each component in the container is of the same size, which is very unnatural, in addition, components are not flexible enough if they must follow a fixed order of rows and columns in the container. In gridbaglayout, you can specify the number of grids contained by each component. The component can retain the original size and can be randomly added to any location of the container in any order, in this way, you can freely arrange the size and location of each component in the container.

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/hfutxrg/archive/2008/12/13/3510165.aspx

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.