Home  >  Article  >  Java  >  How to use Java GUI flow layout manager FlowLayout

How to use Java GUI flow layout manager FlowLayout

王林
王林forward
2023-05-04 14:04:061639browse

Java GUI

The full name of GUI is Graphical User Interface, that is, graphical user interface. It is a graphical interface provided by applications for user operations, including windows, menus, buttons, toolbars and other various graphical interfaces. element.

AWT Overview

AWT is a toolkit for creating graphical user interfaces. It provides some components for implementing graphical interfaces. The JDK provides corresponding components for each component. Java classes, these classes are located in the Java.awt package.

Inheritance relationship in AWT

How to use Java GUI flow layout manager FlowLayout

1. Windows

There are two subclasses in Windows, Frame class and Dialog class, Frame class It is used to create a frame window with a title as the main interface of the program. The Dialog class is used to create a dialog box to interact with the user's information.

2. Panel

Panel is a container and cannot exist alone. It can only exist in Windows and its subclasses. A Panel object represents a rectangular area in which you can To accommodate other components,

package AWT;
 import java.awt.*;
 public class GeZi {
     public static void main(String[] args) {
         Frame f=new Frame("我的世界!");
         //设置窗体的宽和高
         f.setSize(600,300);
         //设置窗体在屏幕中所处的位置(参考是左上角坐标)
         f.setLocation(600,200);
         f.setVisible(true);
     }
 }

How to use Java GUI flow layout manager FlowLayout

Layout Manager

The position and size of the component in the container are determined by the layout manager. There are 5 layout managers provided in the java.awt package, namely FlowLayout (flow layout manager), BorderLayout (border layout manager), GirdLayout (grid layout manager), GirdBagLayout (grid package layout manager) ), CardLayout (Card Layout Manager), each container will use a layout manager by default when it is created. In the program, you can set the layout manager by calling the setLayout() method of the container object, and automatically use the layout manager. Established layout management.

FlowLayout (Flow Layout Manager)

In this layout mode, the container will place components from left to right in the order they are added. When the boundary of the container is reached, the component will be automatically placed at the beginning of the next line. The component can be set to left alignment, center alignment, or right alignment. FlowLayout has three construction methods.

 FlowLayout()//组件默认居中对齐,水平,垂直间距离为5个单位
     FlowLayout(int align)//指定组件相对于容器的对齐方式,水平,垂直间距默认5个单位
     FlowLayout(int align,int hgap,int vgap)//指定组件的对齐方式和水平,垂直间距
rrree

How to use Java GUI flow layout manager FlowLayout

The above is the detailed content of How to use Java GUI flow layout manager FlowLayout. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete