SWT jface formlayout perfect Layout

Source: Internet
Author: User
Tags getcolor

As a matter of fact, it's easy to get started with SWT/jface.


At the beginning, I had to design an interface and use the layout to complete the interface framework. However, the layout of this SWT made me confused,

I basically used up all layout, filllayout, gridlayout, and even sashform,

The page is so unbearable that it cannot be tolerated by myself. In the end, it is impossible and formlayout has not been tried.


I did not really find out the usefulness and characteristics of formlayout during my study. I did not really calculate it... But I suddenly realized the result after careful research. In fact, there are only two layout,

Filllayout and formlayout. The two features are adaptive screens, and formlayout provides something similar to the percentage in HTML,

Filllayout, however, provides the fill effect, and the two do not match each other. It can basically solve the problem in most cases.


Forcibly insert an image:


The following code is provided:

package export;import org.eclipse.swt.SWT;public class TestFormLayout extends Shell {/** * Launch the application. * @param args */public static void main(String args[]) {try {Display display = Display.getDefault();TestFormLayout shell = new TestFormLayout(display);shell.open();shell.layout();while (!shell.isDisposed()) {if (!display.readAndDispatch()) {display.sleep();}}} catch (Exception e) {e.printStackTrace();}}Composite composite_left;Composite composite_right;Composite composite_header;Composite composite_bottom;/** * Create the shell. * @param display */public TestFormLayout(Display display) {super(display, SWT.SHELL_TRIM);setSize(571, 421);setLayout(new FillLayout(SWT.HORIZONTAL));Composite composite_main = new Composite(this, SWT.NONE);composite_main.setLayout(new FormLayout());composite_header = new Composite(composite_main, SWT.BORDER);FormData fd_composite_header = new FormData();fd_composite_header.bottom = new FormAttachment(0, 50);fd_composite_header.right = new FormAttachment(100);fd_composite_header.top = new FormAttachment(0);fd_composite_header.left = new FormAttachment(0);composite_header.setLayoutData(fd_composite_header);Button btnSsss = new Button(composite_header, SWT.NONE);btnSsss.setBounds(107, 10, 80, 27);btnSsss.setText("TT2");Button btnSdfsdf = new Button(composite_header, SWT.NONE);btnSdfsdf.setBounds(212, 10, 80, 27);btnSdfsdf.setText("TT3");Button eeee = new Button(composite_header, SWT.NONE);eeee.setBounds(10, 10, 80, 27);eeee.setText("TT1");composite_bottom = new Composite(composite_main, SWT.BORDER);FormData fd_composite_bottom = new FormData();fd_composite_bottom.top = new FormAttachment(100, -20);fd_composite_bottom.right = new FormAttachment(100);fd_composite_bottom.bottom = new FormAttachment(100);fd_composite_bottom.left = new FormAttachment(0);composite_bottom.setLayoutData(fd_composite_bottom);composite_right = new Composite(composite_main, SWT.NONE);FormData fd_composite_right = new FormData();fd_composite_right.bottom = new FormAttachment(composite_bottom);fd_composite_right.top = new FormAttachment(composite_header, 0);fd_composite_right.left = new FormAttachment(100, -130);fd_composite_right.right = new FormAttachment(composite_header, 0, SWT.RIGHT);composite_right.setLayoutData(fd_composite_right);Label lblNewLabel_1 = new Label(composite_right, SWT.NONE);lblNewLabel_1.setBounds(10, 94, 61, 17);lblNewLabel_1.setText("New Label");//leftcomposite_left = new Composite(composite_main, SWT.NONE);FormData fd_composite_left = new FormData();fd_composite_left.bottom = new FormAttachment(composite_bottom,0);Label label = new Label(composite_bottom, SWT.NONE);label.setText("   \u4E3B\u7A0B\u5E8F\u7248\u672C:");label.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_BLUE));label.setAlignment(SWT.RIGHT);label.setBounds(0, 0, 99, 17);Link link = new Link(composite_bottom, 0);link.setText("<a>\u68C0\u67E5\u66F4\u65B0</a>");link.setBounds(296, 0, 99, 17);Label label_1 = new Label(composite_bottom, SWT.NONE);label_1.setText(" 13.3.7");label_1.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_BLUE));label_1.setBounds(105, 0, 86, 17);Label label_2 = new Label(composite_bottom, SWT.NONE);label_2.setText("\u5DF2\u7ECF\u8FDE\u63A5\u5230\u670D\u52A1\u5668");label_2.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_BLUE));label_2.setBounds(424, 0, 117, 17);fd_composite_left.right = new FormAttachment(composite_right,0);fd_composite_left.top = new FormAttachment(composite_header, 0);fd_composite_left.left = new FormAttachment(0, 0);composite_left.setLayoutData(fd_composite_left);createContents();}/** * Create contents of the shell. */protected void createContents() {}@Overrideprotected void checkSubclass() {// Disable the check that prevents subclassing of SWT components}}

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.