java布局(java布局)

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

java布局(java布局)

java布局(java布局)

GridBagLayout

Free setting component location

Before use, set the layout to setLayout (), and the parameter is empty, that is, setLayout (null).

Create a layout for the component's (x, y) coordinates, as well as

the width and height as parameters.

SetBonds (new, Rectangle (int, x, int, y, int, W, int, H)): parameters are coordinates and width, height.

The setSize (int, int) sets the size of the component

The setLocation (int, int) sets the coordinates of the components Example: Rectangle, re=new, Rectangle (10,10,50,30);

Button.setBounds (re);

Sequential layout (FlowLayout)

Constructor:

FlowLayout (): establish the sequence layout manager by default that the components on each row will be centered;

FlowLayout (int): Specifies alignment, no arguments,

FlowLayout.CENTER, or 1: the components on each row will be centered; arguments FlowLayout.LEFT or 0: left justified; arguments

FlowLayout.RIGHT or 2: right aligned.

FlowLayout (int, int, int): a parameter: FlowLayout.LEFT and FlowLayout.CENTER center, left FlowLayout.RIGHT, right aligned; two parameters: the horizontal spacing between components, in pixels; three parameters: the vertical spacing between components, in pixels.

Method:

SetLayout (): Associate containers with layout managers;

GetAlignment (): get the alignment;

SetAlignment (): sets the alignment;

SetHgap (): sets the horizontal spacing;

SetVgap (): sets the vertical spacing.

Grid layout (GridLayout)

Constructor:

The GridLayout (int, int) parameters are the number of rows and the number of columns. If the row number and column number do not match the actual number, the number of rows is satisfied first.

GridLayout (int, int, int, int) parameter one or two: row number and column number respectively. Parameter three or four: horizontal spacing and vertical spacing, respectively. The default horizontal spacing and vertical spacing are 0.

Method:

SetHgap (): sets the horizontal spacing;

SetVgap (): sets the vertical spacing.

Border layout (BorderLayout)

Constructor:

GridBagLayout (): create a grid bag layout;

GridBagConstraints (): creates a grid bag layout assistant. Properties that are used to set components: layout, size, alignment, etc..

Steps to create grid bags:

1) creates a GridBagLayout object and specifies it as the current layout manager;

2) create a GridBagConstraints instance;

3) set the constraint for the component;

4) tell the layout manager the components and their

constraints;

5) add components to a container.

Method:

BuildConstraints (): accepts seven arguments: a

GridBagConstraints object and six integers:

Gridx and gridy: the coordinates of the cells in which the component is located;

Gridwidth and gridheight: the number of cells, rows, and rows spanned by the component;

Weightx and weighty: sets the ratio of rows and columns.

SetConstraints (): associate with an object. Two parameters are received: the component and the constraints of the component. Constraints: fill and anchor.

相关文档
最新文档