Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Java GUI streaming layout Manager FlowLayout

2025-03-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article editor for you a detailed introduction of "Java GUI streaming layout manager FlowLayout how to use", detailed content, clear steps, details handled properly, I hope that this "Java GUI streaming layout manager FlowLayout how to use" article can help you solve doubts, following the editor's ideas slowly in-depth, together to learn new knowledge.

Java GUI

The full name of GUI is Graphical User Interface, which is the graphical interface that the application provides to the user, including windows, menus, buttons, toolbars and various other graphical interface elements.

Overview of AWT

AWT is a toolkit for creating a graphical user interface that provides components for implementing a graphical interface, and corresponding Java classes are provided in JDK for each component, all of which are located in the Java.awt package.

Inheritance relationship in AWT

1 、 Windows

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

2 、 Panel

Panel is a container that cannot exist alone and can only exist in Windows and its subclasses. A Panel object represents a rectangular area in which other components can be accommodated.

Package AWT; import java.awt.*; public class GeZi {public static void main (String [] args) {Frame f=new Frame ("my World!"); / / set the width and height of the form f.setSize (600300); / / set the position of the form on the screen (reference is the upper-left coordinates) f.setLocation (600200); f.setVisible (true);}}

Layout tube

The location and size of components in the container is determined by the layout manager. Five layout managers are provided in the java.awt package, namely FlowLayout (flow layout Manager), BorderLayout (Border layout Manager), GirdLayout (Grid layout Manager), GirdBagLayout (Grid package layout Manager) and CardLayout (Card layout Manager). Each container uses a layout manager by default when it is created, which can be set by calling the setLayout () method of the container object. Automatically manage the layout of the build through the layout manager.

FlowLayout (streaming layout Manager)

In this layout, the container places the components from left to right in the order in which they are added. When the boundary of the container is reached, the component is automatically placed at the beginning of the next line. You can set the component to be left-aligned, center-aligned, or right-aligned. FlowLayout has three construction methods.

FlowLayout () / / components are centered by default, horizontal, vertical distance is 5 units FlowLayout (int align) / / specifies the alignment of components relative to the container, horizontal and vertical spacing defaults to 5 units FlowLayout (int align,int hgap,int vgap) / / specifies the alignment and horizontal, vertical spacing of components package AWT; import java.awt.* Public class LuiSi {public static void main (String [] args) {final Frame f=new Frame ("FlowLayout"); / / set layout Manager to FlowLayout with left alignment of all components, horizontal spacing of 20, vertical spacing of 30 f.setLayout (new FlowLayout (FlowLayout.LEFT,20,30)); f.setSize (220300); f.setLocation (300200); f.add (new Button ("first button")) F.add (new Button ("2nd button")); f.add (new Button ("3rd button")); f.add (new Button ("4th button")); f.add (new Button ("5th button")); f.add (new Button ("6th button")); f.setVisible (true);}}

After reading this, the article "how to use Java GUI streaming layout Manager FlowLayout" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it to understand it. If you want to know more about related articles, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report