While Java can pinpoint components in pixels, there will be some display differences in different systems, so that the display is not the same, so Java provides a layout manager to make the graphical interface written with good platform independence.
Note: All layout managers are used for containers, including top-level containers and intermediate containers. Several layout managers have been introduced earlier, and this article will show how the FlowLayout layout is used
FlowLayout (Flow layout)
The components in a container using the FlowLayout layout are arranged in the order in which they are joined (centered, left, right, aligned) from left to right, with a row full (that is, after the component exceeds the container width) to the next line to begin the arrangement.
Common constructors for the FlowLayout class
constructor function
FlowLayout ()------ Constructs a new flowlayout, which is centered by default, and the default horizontal and vertical clearance is 5 pixels
flowlayout (int align) ------Five parameter values and meanings are as follows:
0 or Flowlayout.left, control left justified
1 or Flowlayout.center, center-aligned
2 or Flowlayout.right, right-justified
3 or flowlayout.leading, the control corresponds to the start edge of the container direction
4 or flowlayout.trailing, the control corresponds to the end edge of the container direction
Left-justified if it is an integer other than 0, 1, 2, 3, 4
flowlayout (int align, int hgap, int vgap) --------creates a new flow layout manager that has the specified alignment and the specified horizontal and vertical gaps
Method
Void setalignment (int align)-----Set the alignment of this layout.
void Sethgap (int hgap)----------Sets the horizontal gap between components and the edges of the component and the container.
void Setvgap (int vgap)---------Sets the vertical gap between components and the edges of the component and the Container.
FlowLayout Instances
<span style= "color: #330033;" >import java.awt.button;import Java.awt.flowlayout;import Javax.swing.jframe;public class FlowLayOutDemo {public static void Main (string[] args) {JFrame fr=new JFrame ("Streaming layout example"); Fr.setlayout (new FlowLayout (flowlayout.center,20,5)) ;//Flow layout, center align for (int i = 0; i < ++i) {fr.add (New button +i)} Set the window to the optimal size fr.pack (); fr.setvisible (true);} }</span>
After pulling the window
FlowLayout layout of the Java Swing layout manager