Java gridbaglayout gridbagconstraints

Source: Internet
Author: User

 

Each widget has a natural height and a natural width (for example, jbutton height and width are determined by the text length), and a display area (Green Box, blue box, and red box in the figure ), the natural width and height of jtextarea are the width and height of the display area. For example

The height of the display control occupied by each widget in one row is the same. The width of each control in one column is the same. For the preceding three controls (two jbuttons and one jtextarea), set constraints. fill
= Gridbagconstraints. Vertical; in this way, you can see their display areas:

Extra horizontal space (extra horizontal space), that is, H1 + H2 in Figure 1

VariableWidthxIs to allocate additional horizontal space according to the widthx value of each control in a row. For example, set the first control widthx to 8 and the second widthx to 0, if the third widthx is set to 2, the result is as follows:

(Set constraints. Fill = gridbagconstraints. Both to conveniently observe the display space of each control)

We can see that H1 + H2 is divided by the first and third controls according to the ratio of. If width is 0, no additional space is allocated.

 Widthy.

Gridx,Gridy

The cell where the left edge line of the control (container from left to right) is located, the cell where the edge line on the control is located, and the green control's gridx and gridy are () Black controls are)

The default value is-1, which is placed close to the previous or previous control.

Gridwidth, gridheight

The number of cells that the control occupies in one row and the number of cells in one column. 0 indicates that all cells in one row and one column are occupied.

Fill

When the display area of the control is larger than the natural area, it determines how to fill it. Horizontal horizontal fill, vertical fill, both horizontal fill, vertical fill, none do not fill.

 Insets: insets

The size of the blank area on the edge of the widget and the table space.

 

 

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.