FORTUNE

THE WAY TO THE MASTER...
posts - 49, comments - 18, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

SWT Layout - RowLayout

Posted on 2006-03-08 19:01 fortune 阅读(955) 评论(0)  编辑  收藏 所属分类: 我的学习笔记
RowLayout要比FillLayout使用多些,每个widget的长度和宽度都可以通过方法setLayout()设定widget的RowData。

Type域
指定按行或列排列  如: new RowLayout(SWT.HORIZONTAL);default:horizontal

Wrap域
指定该行或列空间不足放下当前控件时是否自动换行;default:true

Pack域
指定Layout中的widgets是否采用它们的自然大小,如果pack为false则所有widget强制为相同大小default:true

Justify域
true表明Layout中的所有widgets每行都从左到右平均距离展开default:false

MarginLeft, MarginTop, MarginRight, MarginBottom and Spacing

前面4个是指定于边框距离的,spacing指定widget之间的间隔

   RowLayout rowLayout = new RowLayout();

   rowLayout.wrap = false;

   rowLayout.pack = false;

   rowLayout.justify = true;

   rowLayout.type = SWT.VERTICAL;

   rowLayout.marginLeft = 5;

   rowLayout.marginTop = 5;

   rowLayout.marginRight = 5;

   rowLayout.marginBottom = 5;

   rowLayout.spacing = 0;

   shell.setLayout(rowLayout)

 

下面的代码使用RowData对象来改变button的大小

import org.eclipse.swt.*;

import org.eclipse.swt.widgets.*;

import org.eclipse.swt.layout.*;

 

public class RowDataExample {

 

   public static void main(String[] args) {

       Display display = new Display();

       Shell shell = new Shell(display);

       shell.setLayout(new RowLayout());

       Button button1 = new Button(shell, SWT.PUSH);

       button1.setText("Button 1");

       button1.setLayoutData(new RowData(50, 40));

       Button button2 = new Button(shell, SWT.PUSH);

       button2.setText("Button 2");

       button2.setLayoutData(new RowData(50, 30));

       Button button3 = new Button(shell, SWT.PUSH);

       button3.setText("Button 3");

       button3.setLayoutData(new RowData(50, 20));

       shell.pack();

       shell.open();

       while (!shell.isDisposed()) {

          if (!display.readAndDispatch()) display.sleep();

       }

   }

}

 

参考:http://www.eclipse.org/articles/Understanding%20Layouts/Understanding%20Layouts.htm


只有注册用户登录后才能发表评论。


网站导航: