zoukankan      html  css  js  c++  java
  • SWT的GridData一些参数的图示

    1. 参数;verticalSpan

    GridData gridData=new GridData();
    gridData.verticalSpan=100;

    final Text nameText=new Text(shell, SWT.BORDER);
    nameText.setLayoutData(gridData);

      可以发现,verticalSpan代表的是控件占据的行数。

    若代码如下:

    public class LBMShow{
        public static void main(String args[]){
            final Display display=Display.getDefault();
            final Shell shell=new Shell(display);
            shell.setText("Hello");
            GridLayout gridLayout=new GridLayout(2, true);
            GridData gridData=new GridData();
            gridData.verticalSpan=100;
            shell.setLayout(gridLayout);
            
            
            final Label nameLabel=new Label(shell, SWT.BORDER);
            nameLabel.setText("name: ");
            final Text nameText=new Text(shell, SWT.BORDER);
            nameText.setText("1");
            nameLabel.setLayoutData(gridData);
            nameText.setLayoutData(gridData);
            
            final Label passwdLabel=new Label(shell, SWT.BORDER);
            passwdLabel.setText("password: ");
            final Text passwdText=new Text(shell, SWT.BORDER);
            passwdText.setText("2");
            
            final Button button = new Button(shell, SWT.NONE);
            button.setText("登录");
            //button.setBounds(32, 28, 58, 22);
            shell.open();
            //shell.layout();
            
             //消息循环
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
        }
    }

    则效果如下:

    2.参数: horizontalSpan

      horizontalSpan代表的是:一个控件所占列数,默认一行包含1个位置,所以若将其设置为2时,这个控件会独占一行。

    代码:

    public class LBMShow{
        public static void main(String args[]){
            final Display display=Display.getDefault();
            final Shell shell=new Shell(display);
            shell.setText("Hello");
            GridLayout gridLayout=new GridLayout(2, true);
            GridData gridData=new GridData();
            gridData.horizontalSpan=2;
            shell.setLayout(gridLayout);
            
            
            final Label nameLabel=new Label(shell, SWT.BORDER);
            nameLabel.setText("name: ");
            final Text nameText=new Text(shell, SWT.BORDER);
            nameText.setText("1");
            nameLabel.setLayoutData(gridData);
            nameText.setLayoutData(gridData);
            
            final Label passwdLabel=new Label(shell, SWT.BORDER);
            passwdLabel.setText("password: ");
            final Text passwdText=new Text(shell, SWT.BORDER);
            passwdText.setText("2");
            
            final Button button = new Button(shell, SWT.NONE);
            button.setText("登录");
            //button.setBounds(32, 28, 58, 22);
            shell.open();
            //shell.layout();
            
             //消息循环
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
        }
    }

    效果;

    3.参数: grabExcessHorizontalSpace

      这个参数只有true或false的选择,默认为false。他表示是否填充剩余的水平空间。

    代码:

    public class LBMShow{
        public static void main(String args[]){
            final Display display=Display.getDefault();
            final Shell shell=new Shell(display);
            shell.setText("Hello");
            GridLayout gridLayout=new GridLayout(2, true);
            GridData gridData=new GridData();
            gridData.grabExcessHorizontalSpace=true;
            shell.setLayout(gridLayout);
            
            
            final Label nameLabel=new Label(shell, SWT.BORDER);
            nameLabel.setText("name: ");
            final Text nameText=new Text(shell, SWT.BORDER);
            nameText.setText("1");
            nameLabel.setLayoutData(gridData);
            nameText.setLayoutData(gridData);
            
            final Label passwdLabel=new Label(shell, SWT.BORDER);
            passwdLabel.setText("password: ");
            final Text passwdText=new Text(shell, SWT.BORDER);
            passwdText.setText("2");
            
            final Button button = new Button(shell, SWT.NONE);
            button.setText("登录");
            //button.setBounds(32, 28, 58, 22);
            shell.open();
            //shell.layout();
            
             //消息循环
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
        }
    }

    效果:

    4. 参数: grabExcessVerticalSpace

        此参数表示控件是否填充垂直的剩余空间。

    代码:

    public class LBMShow{
        public static void main(String args[]){
            final Display display=Display.getDefault();
            final Shell shell=new Shell(display);
            shell.setText("Hello");
            GridLayout gridLayout=new GridLayout(2, true);
            GridData gridData=new GridData();
            gridData.grabExcessVerticalSpace=true;
            shell.setLayout(gridLayout);
            
            
            final Label nameLabel=new Label(shell, SWT.BORDER);
            nameLabel.setText("name: ");
            final Text nameText=new Text(shell, SWT.BORDER);
            nameText.setText("1");
            nameLabel.setLayoutData(gridData);
            nameText.setLayoutData(gridData);
            
            final Label passwdLabel=new Label(shell, SWT.BORDER);
            passwdLabel.setText("password: ");
            final Text passwdText=new Text(shell, SWT.BORDER);
            passwdText.setText("2");
            
            final Button button = new Button(shell, SWT.NONE);
            button.setText("登录");
            //button.setBounds(32, 28, 58, 22);
            shell.open();
            //shell.layout();
            
             //消息循环
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
        }
    }

    效果:

    5.参数: widthHint

      这个参数的意思是控件的最小宽度,可以设定控件的宽度

    代码;

    public class LBMShow{
        public static void main(String args[]){
            final Display display=Display.getDefault();
            final Shell shell=new Shell(display);
            shell.setText("Hello");
            GridLayout gridLayout=new GridLayout(2, true);
            GridData gridData=new GridData();
            gridData.widthHint=500;
            shell.setLayout(gridLayout);
            
            
            final Label nameLabel=new Label(shell, SWT.BORDER);
            nameLabel.setText("name: ");
            final Text nameText=new Text(shell, SWT.BORDER);
            nameText.setText("1");
            nameLabel.setLayoutData(gridData);
            nameText.setLayoutData(gridData);
            
            final Label passwdLabel=new Label(shell, SWT.BORDER);
            passwdLabel.setText("password: ");
            final Text passwdText=new Text(shell, SWT.BORDER);
            passwdText.setText("2");
            
            final Button button = new Button(shell, SWT.NONE);
            button.setText("登录");
            //button.setBounds(32, 28, 58, 22);
            shell.open();
            //shell.layout();
            
             //消息循环
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
        }
    }

    效果:

    6.参数: heightHint

      这个参数表示控件的最小高度。

    代码:

    public class LBMShow{
        public static void main(String args[]){
            final Display display=Display.getDefault();
            final Shell shell=new Shell(display);
            shell.setText("Hello");
            GridLayout gridLayout=new GridLayout(2, true);
            GridData gridData=new GridData();
            gridData.heightHint=500;
            shell.setLayout(gridLayout);
            
            
            final Label nameLabel=new Label(shell, SWT.BORDER);
            nameLabel.setText("name: ");
            final Text nameText=new Text(shell, SWT.BORDER);
            nameText.setText("1");
            nameLabel.setLayoutData(gridData);
            nameText.setLayoutData(gridData);
            
            final Label passwdLabel=new Label(shell, SWT.BORDER);
            passwdLabel.setText("password: ");
            final Text passwdText=new Text(shell, SWT.BORDER);
            passwdText.setText("2");
            
            final Button button = new Button(shell, SWT.NONE);
            button.setText("登录");
            //button.setBounds(32, 28, 58, 22);
            shell.open();
            //shell.layout();
            
             //消息循环
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
        }
    }

    效果:

    7.参数;horizontalAlignment和verticalAlignment还没弄出来。

  • 相关阅读:
    LeetCode_167. Two Sum II
    LeetCode_160. Intersection of Two Linked Lists
    LeetCode_155. Min Stack
    LeetCode_141. Linked List Cycle
    LeetCode_136. Single Number
    LeetCode_125. Valid Palindrome
    HTML解析类 ,让你不使用正则也能轻松获取HTML相关元素 -C# .NET
    .net 根据匿名类生成实体类,根据datatable生成实体类,根据sql生成实体类
    将form表单元素转为实体对象 或集合 -ASP.NET C#
    ASP.NET 图片上传工具类 upload image简单好用功能齐全
  • 原文地址:https://www.cnblogs.com/wangjiyuan/p/layout.html
Copyright © 2011-2022 走看看