Notes for SWT Layout

Source: Internet
Author: User

Notes for SWT Layout

In the past two days, I led the team members to develop a very complex interface. Because the team members are not very familiar with SWT layout, many problems have emerged on the interface. Sometimes an exception occurs, because layout and layoutdata do not match, and sometimes the screen is not displayed. Always, the problems that can be generated are basically met.
The current development idea is to first draw the interface with SWT designer and then manually rebuild and organize it. SWT designer cannot identify the restructured code. Therefore, it is not feasible to rely solely on visualization tools, but also to be very familiar with SWT interface encoding. Therefore, it is critical to master SWT layout.
Note the following when creating your own composite:
1. The composite passed in from the outside must be used only once, that is, when super (parent, style); is used, and the father of all the controls in the future will be the composite itself. Do not use parent anywhere else. Otherwise, it is likely to interfere with the content in the parent, resulting in display Errors for itself and other controls in the parent.

2. layout must be set for each composite container; otherwise, nothing may be displayed. In general, gridlayout is set. If Composite itself places a control, for example, placing a table, filllayout can also be used. Gridlayout is recommended for beginners. Otherwise, layout and layoutdata do not match easily. If the interface is complex, the problem is hard to find. Gridlayout can completely replace other layout to meet various requirements (if there are overlapping controls, it will not work, and formlayout should be used ).
The following is a piece of source code. We recommend that you follow this method to build the interface.

 

Public class testcomposite extends composite ......{

Private text;
/***//***//***//**
* Create the Composite
* @ Param parent
* @ Param Style
*/
Public testcomposite (composite parent, int style )......{
Super (parent, style );
Setlayout (New gridlayout ());
Createarea (this );
}
Private void createarea (composite parent )......{
TEXT = new text (this, SWT. Border );
Text. setlayoutdata (New griddata (SWT. Fill, SWT. Center, true, false ));

Final button = new button (this, SWT. None );
Button. settext ("button ");
}

@ Override
Public void dispose ()......{
Super. Dispose ();
}
}

 

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.