Study Notes: Understanding layouts in SWT (1)

Source: Internet
Author: User

20060628

Study Notes: Understanding layouts in SWT

Original article: Understanding layouts in SWT

See eclipse help: Platform Plug-in developer guide-> programmer's Guide-> Standard Widget Tookit-> layouts.

Or: http://help.eclipse.org/help30/topic/org.eclipse.platform.doc.isv/guide/swt_layouts.htm (3.0 help)

The online 3.2 help is different from the online 3.0 help.

 

Although layout is often used, it cannot be remembered. You need to open this article or eclipse help every time to query layout usage.

 

Standard Layout:

· Filllayout-lays out equal-sized widgets in a single row or column

· Rowlayout-lays out widgets in a row or rows, with fill, wrap, and spacing options

· Gridlayout-lays out widgets in a grid

· Formlayout-lays out widgets using an attachment model.

· Stacklayout-creates a conceptual stack of Widgets

· Custom layouts-custom Layout

 

Only the first three layout types are mentioned in the original article. However, there are actually 6 layout types by searching the relevant documentation and code of 3.2.

 

 

Filllayout

The simplest layout.

The widgets on the parent composite will fill all the space. Expand the parent composite, and the widgets will also become larger, with the same size. It can be divided into horizontal fill and vertical fill, determined by filllayout. type.

Try again. Whether the type is SWT. Vertical or SWT. horizontal, the minimum height that parent composite can pull is 0. The minimum width is different.

When SWT. Horizontal and parent composite are pulled to the smallest width, only the content of the widget with the smallest natural width is visible. It is suspected that the minimum width is determined by the component with the smallest natural width.

When SWT. Vertical and parent composite are pulled to the smallest width, the content of each widget is visible. I think the minimum width should be determined by the component with the largest natural width.

 

 

Rowlayout

When rowlayout is set for a component, the children widget of this component will arrange the position with the set layout.

 

Wrap:

True: if the current row does not have enough space (that is to say, a child widget cannot be displayed), the Child widget contained in it will be displayed in the next row.

False: Of course, the widget is placed in this line even if it cannot be displayed, which means that some of the widgets are invisible.

 

The default value is true.

I tried to execute the rowlayout examples code in the original text. I wanted to try setting wrap to true. What would happen if I pulled the shell width to the second line even if it didn't show up. The result shows that the shell size cannot be so small. The minimum width that shell can pull is slightly larger than the maximum width of all its children widgets. Shell height does not seem to have any restrictions. What if you want to pull it.

 

Pack:

True: The component size is its natural size. For example, a composite's rowlayout. Pack = true has a button on this composite. The content displayed by the button is "button 1", so the size of the button will just accommodate the string "button 1. That is to say, the width of the button is determined based on the content displayed. So when the button displays different content, the width of the button is different.

False: The component is fully occupied with available space. It is similar to filllayout.

The default value is true.

 

Justify

True: The component tries its best to stretch the space occupied by the component from left to right (the width occupied by the component, rather than the width of the component itself ). When the parent composite becomes wider, the extra space will be snatched by each component, although the component does not necessarily need that large space.

False: this will not happen.

The default value is false.

If both pack and justify are true, each component is its natural size, but there is extra space between each component. It can be said that the component is standing in a pitfall.

 

Marginleft, margintop, marginright, marginbottom and spacing

These values control the space between the widget and the widget, and control the only-seen space (margin) between the widget and the parent composite ). They are measured in pixels ). By default, the values of margin and spacing are three.

In this article, I checked the code of 3.0 and found that the default value of margin is 0 and spacing is 3. It is estimated that the SWT version of the original author is relatively old.

 

Rowdata

Rowdata is used to control the widget size. Before 3.1, it had two fields: width and height. These two attributes are self-evident. Since 3.1, an exclude has been added. The help document explains this: exclude informs the layout to ignore this control When sizing and positioning controls. Its default value is false, which is equivalent to 3.1 without this variable. When the value is true, this widget will disappear, and I am a bit puzzled. I don't understand.

For the exclude variable, we can find this webpage from eclipse.org: response? REV = Head & Content-Type = text/vnd. viewcvs-markup. Well, I finally understood the code snippet175.

When rowdata. Exclude = true for this widget (set to a), parent composite layout its children widget when a does not exist. That is to say, after widget a is created, the position of the component created after widget a is the position of widget a, so that widget a is overwritten. If it is set to false, it will be the same as ours.

But there is a problem. If the exclude of A is originally false, I want to change it to true now. In this case, we need to re-layout the parent composite (AS A does not exist for layout ), but it is strange that a overwrites the widget next to it, rather than the widget next to it. Is it because a modifies rowdata that layout is performed on a only after other widgets of parent composite are layout? This is to be further verified.

 

There are almost no bugs in the past two days. I am idle and will continue learning tomorrow.

 

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.