formlayout布局,datetime演示

package com.fengmanfei.ch7;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
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.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner;

public class Test {
    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        FormLayout layout = new FormLayout();
        shell.setLayout(layout);
        shell.setSize(432,300);
       
        Group startTimeGroup = new Group(shell, SWT.SHADOW_IN);
        startTimeGroup.setText("Start Time");
        startTimeGroup.setSize(200, 200);
        startTimeGroup.setLayout(new RowLayout(SWT.VERTICAL));
        Button startCheckButton = new Button(startTimeGroup, SWT.CHECK);
        startCheckButton.setText("Star&t by the below time");
        startCheckButton.setSize(60,15);
        Spinner startSpinner = new Spinner(startTimeGroup, SWT.NONE);
       
        FormData data = new FormData();
        data.top = new FormAttachment(0, 5);
        data.left = new FormAttachment(0, 5);
        data.bottom = new FormAttachment(50, -5);
        data.right = new FormAttachment(50, -5);
        startTimeGroup.setLayoutData(data);
       
        Composite buttonsComposite = new Composite(shell, SWT.NONE);
        GridLayout gridLayout = new GridLayout();
        gridLayout.marginHeight = 0;
        gridLayout.marginWidth = 0;
        buttonsComposite.setLayout(gridLayout);
        Button startButton = new Button(buttonsComposite, SWT.PUSH);
        startButton.setText("&Start");
        GridData gridData = new GridData(GridData.FILL_BOTH);
        startButton.setLayoutData(gridData);
        Button cancelButton = new Button(buttonsComposite, SWT.PUSH);
        cancelButton.setText("&Cancel");
        gridData = new GridData(GridData.FILL_BOTH);
        cancelButton.setLayoutData(gridData);
        data = new FormData();
        data.top = new FormAttachment(0, 5);
        data.left = new FormAttachment(startTimeGroup, 5);
        data.bottom = new FormAttachment(50, -5);
        data.right = new FormAttachment(100, -5);
        buttonsComposite.setLayoutData(data);
       
        Group stopTimeGroup = new Group(shell, SWT.SHADOW_IN);
        stopTimeGroup.setText("Stop Time");
        stopTimeGroup.setSize(200, 200);
        stopTimeGroup.setLayout(new RowLayout(SWT.VERTICAL));
        Button stopCheckButton = new Button(stopTimeGroup, SWT.CHECK);
        stopCheckButton.setText("Sto&p by the below time");
        stopCheckButton.setSize(60,15);
        Spinner stopSpinner = new Spinner(stopTimeGroup, SWT.NONE);
       
        data = new FormData();
        data.top = new FormAttachment(startTimeGroup, 5);
        data.left = new FormAttachment(0, 5);
        data.bottom = new FormAttachment(100, -5);
        data.right = new FormAttachment(50, -5);
        stopTimeGroup.setLayoutData(data);
               
        Composite labelsComposite = new Composite(shell, SWT.NONE);
        gridLayout = new GridLayout();
        gridLayout.marginHeight = 0;
        gridLayout.marginWidth = 0;
        labelsComposite.setLayout(gridLayout);
        Label remainlLabel = new Label(labelsComposite, SWT.PUSH);
        remainlLabel.setText("remain:");
        gridData = new GridData(GridData.FILL_BOTH);
        remainlLabel.setLayoutData(gridData);
        data = new FormData();
        data.top = new FormAttachment(buttonsComposite, 30);
        data.left = new FormAttachment(stopTimeGroup, 5);
        data.bottom = new FormAttachment(100, -5);
        data.right = new FormAttachment(100, -5);
        labelsComposite.setLayoutData(data);

        shell.pack();
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();
    }
}



package com.fengmanfei.ch7;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class FormLayoutSample {

    public static void main(String[] args) {
        Display display = new Display ();
          final Shell shell = new Shell (display);
          shell.setLayout(new FillLayout());

          Button open = new Button (shell, SWT.PUSH);
          open.setText ("Open Dialog");
          open.addSelectionListener (new SelectionAdapter () {
            public void widgetSelected (SelectionEvent e) {
              final Shell dialog = new Shell (shell, SWT.DIALOG_TRIM);
              dialog.setLayout (new GridLayout (3, false));

              final DateTime calendar = new DateTime (dialog, SWT.CALENDAR | SWT.BORDER);
              final DateTime date = new DateTime (dialog, SWT.DATE | SWT.SHORT);
              final DateTime time = new DateTime (dialog, SWT.TIME | SWT.SHORT);

              new Label (dialog, SWT.NONE);
              new Label (dialog, SWT.NONE);
              Button ok = new Button (dialog, SWT.PUSH);
              ok.setText ("OK");
              ok.setLayoutData(new GridData (SWT.FILL, SWT.CENTER, false, false));
              ok.addSelectionListener (new SelectionAdapter () {
                public void widgetSelected (SelectionEvent e) {
                  System.out.println ("Calendar date selected (MM/DD/YYYY) = " + (calendar.getMonth () + 1) + "/" + calendar.getDay () + "/" + calendar.getYear ());
                  System.out.println ("Date selected (MM/YYYY) = " + (date.getMonth () + 1) + "/" + date.getYear ());
                  System.out.println ("Time selected (HH:MM) = " + time.getHours () + ":" + time.getMinutes ());
                  dialog.close ();
                }
              });
              dialog.setDefaultButton (ok);
              dialog.pack ();
              dialog.open ();
            }
          });
          shell.pack ();
          shell.open ();
         
          while (!shell.isDisposed ()) {
            if (!display.readAndDispatch ()) display.sleep ();
          }
          display.dispose ();
    }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值