Java panel usage and five interface layout methods (flowlayout, borderlayout, gridlayout, cardlayout, and boxlayout)

Source: Internet
Author: User

 

(Jpanel) a panel is a lightweight container. Because it is not a top-level container, it must be placed on advanced containers such as jframe, so that you can) the complex application interface is built through panel and five interface layout managers.

The following describes five interface layout managers:

Borderlayout:

This is a border layout for container layout. It can arrange container components and adjust their size to meet the following five areas: north, south, east, west, and middle. Each region can contain up to one component and is identified by corresponding constants:NORTH,SOUTH,EAST,WEST,CENTER. When adding a component to a container using the border layout, use one of the five constants, for example:

          Panel p = new Panel();               p.setLayout(new BorderLayout());               p.add(new Button("Okay"), BorderLayout.SOUTH);FLowLayout:
The stream layout is used to arrange components in a directed stream, which is very similar to text lines in a section. The direction of the stream depends on the container'scomponentOrientationAttribute,
It may be one of the following two values:
  • ComponentOrientation.LEFT_TO_RIGHT
  • ComponentOrientation.RIGHT_TO_LEFT
Streaming layout is generally used to arrange buttons in the panel. It places buttons horizontally until there is no suitable button on the same line.
GirdLayout:
The gridlayout class is a layout processor that arranges container components in the form of rectangular grids. Containers are divided into rectangles of the same size,
Place a component in a rectangle.
 BoxLayout:          
Allows vertical or horizontal layout of layout managers for multiple components. These components will not be packaged, so for example, vertically arranged components are still vertically arranged when the frame is adjusted.

 

Nesting multiple panels using different combinations of horizontal and vertical components is similar to gridbaglayout, but not that complex. The figure shows two horizontally arranged panels, each of which contains three vertically arranged widgets.

 

Cardlayout:

Similar to the concept of layers, you can use cardlayout on a form or panel to take the customized UI as a layer, so that when there are multiple layers, you can switch between layers.

Similar to a flop.

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.