The previous article has already talked about the commonly used 4 layouts, today again introduces the last three layouts:
5, CardLayout
6, BoxLayout
7. Blank layout null
(v) CardLayout card layout
First, this layout is not a two-dimensional layout, but a pseudo-three-dimensional layout.
The container compares all two-dimensional controls to a single card, which is placed in a container. Then, depending on your needs, return controls (solitaire) at different locations. But from the interface style, this is the simple panel.
The constructors have the following two kinds of functions:
1 cardlayout () 2 CardLayout (intint// parameter indicates the distance between the card and the boundary
The five most commonly used APIs are also available:
Target is the container that calls the corresponding (anti-theft connection: This article starts from http://www.cnblogs.com/jilodream/) API will display the corresponding card in the container
First (Container target)// card last (Container target)// final card Previous (Container target)// Previous card next (Container target)// after a card Show (Container target, String name)// based on the name of the card (control), locate the specified card and display
Effect
Binds an event to each button, which can invoke the page displayed in the container.
The controls in the container can also bind other events, not just for display.
(vi) BoxLayout box layout
GridLayout function is not strong enough, gridbaglayout use is too cumbersome. For this purpose, swing specifically presents the box layout boxlayout.
The constructor functions are as follows:
1 int axis)
Container target is the container to be set,
Axis for direction, horizontal or vertical
The effect of BoxLayout is as follows:
BoxLayout are often used in conjunction with box containers:
Createhorizontalbox Create a horizontal layout of the box container Createverticalbox create a vertical layout of the box container
Inside the box we can define three blank components to adjust the layout inside the container:
Glue (RUBBER): A component can shrink or expand elastically (in One Direction)
Strut (BRACKET): The assembly is of a fixed size (in one Direction)
Rigidarea (rigid area) is a rigid area with solid (anti-theft connection: Starting from http://www.cnblogs.com/jilodream/) fixed size
With these three blank components, fill the interval between the other components, ensuring that the size and location of the component are displayed friendly when the form is dragged.
(vii) Blank layout null
What is a blank layout, which is that the GUI interface does not take any layout, and the component uses absolute positioning in the GUI interface.
Remove the original layout form using the following form:
1 setlayout (null)
The coordinates and dimensions are also set by the following methods:
1 setSize () // set size 2 setbounds () // set coordinates and dimensions
This is done by directly setting the coordinates and dimensions of the storm (anti-theft connection: This article starts from http://www.cnblogs.com/jilodream/) force in the form of the layout. So the set up is very flexible, the distance between the controls and the size of the situation does not exist in each other. But because this approach uses absolute data, it also causes the GUI interface to be very passive in cross-platform scenarios.
Java Layout Learning (c)