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还没弄出来。