FormLayout实现自适应窗口

package test;

import java.awt.Dimension;
import java.awt.Toolkit;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;

public class MainWindow {

    protected Shell shell;

    /**
     * Launch the application.
     * @param args
     */
    public static void main(String[] args) {
        try {
            MainWindow window = new MainWindow();
            window.open();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Open the window.
     */
    public void open() {
        Display display = Display.getDefault();
        createContents();
        shell.open();
        shell.layout();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }

    /**
     * Create contents of the window.
     */
    protected void createContents() {
        shell = new Shell();
//        shell.setFullScreen(true);
        shell.setMaximized(true);
        shell.setText("SWT Application");
        int topNumerator =70;
        FormLayout layout =new FormLayout();
        shell.setLayout (layout);
        //顶部
        Composite cTop=new Composite(shell,SWT.NONE);
        FormData fdTop=new FormData();
        fdTop.top =new FormAttachment(0);
        fdTop.right=new FormAttachment(100);
        fdTop.bottom=new FormAttachment(topNumerator);
        fdTop.left=new FormAttachment(0);
        cTop.setLayoutData(fdTop);
       
        //顶部子布局
        cTop.setLayout(new FillLayout());
        List lLeft=new List(cTop,SWT.MULTI);
        List lcenter=new List(cTop,SWT.MULTI);
        List lright=new List(cTop,SWT.MULTI);
        //底部
        Composite cBottom=new Composite(shell,SWT.BORDER);
        FormData fdBottom=new FormData();
        fdBottom.top=new FormAttachment(topNumerator);
        fdBottom.right=new FormAttachment(100);
        fdBottom.bottom=new FormAttachment(100);
        fdBottom.left=new FormAttachment(0);
        cBottom.setLayoutData(fdBottom);
        //底部子布局
        cBottom.setLayout(new RowLayout());
        Button b1=new Button(cBottom,SWT.PUSH);
        b1.setText("button1");
        Button b2=new Button(cBottom,SWT.PUSH);
        b2.setText("button2");
        Button b3=new Button(cBottom,SWT.PUSH);
        b3.setText("button3");
        Button b4=new Button(cBottom,SWT.PUSH);
        b4.setText("button4");
        Button b5=new Button(cBottom,SWT.PUSH);
        b5.setText("button5");
    }

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值