FlowLayout layout of the Java Swing layout manager

Source: Internet
Author: User

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

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.