java swt griddata_SWT的GridData一些参数的图示

java swt griddata_SWT的GridData一些参数的图示1.参数;verticalSpanGridDatagridData=newGridData();gridData.verticalSpan=100;finalTextnameText=newText(shell,SWT.BORDER);nameText.setLayoutData(gridData);可以发现,verticalSpan代表的是控件占据的行数。若代码如下:public…

大家好,又见面了,我是你们的朋友全栈君。

1. 参数;verticalSpan

GridData gridData=new GridData();

gridData.verticalSpan=100;

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

nameText.setLayoutData(gridData);

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

若代码如下:

public classLBMShow{public static voidmain(String args[]){final Display display=Display.getDefault();final Shell shell=newShell(display);

shell.setText(“Hello”);

GridLayout gridLayout=new GridLayout(2, true);

GridData gridData=newGridData();

gridData.verticalSpan=100;

shell.setLayout(gridLayout);final Label nameLabel=newLabel(shell, SWT.BORDER);

nameLabel.setText(“name: “);final Text nameText=newText(shell, SWT.BORDER);

nameText.setText(“1”);

nameLabel.setLayoutData(gridData);

nameText.setLayoutData(gridData);final Label passwdLabel=newLabel(shell, SWT.BORDER);

passwdLabel.setText(“password: “);final Text passwdText=newText(shell, SWT.BORDER);

passwdText.setText(“2”);final Button button = newButton(shell, SWT.NONE);

button.setText(“登录”);//button.setBounds(32, 28, 58, 22);

shell.open();//shell.layout();//消息循环

while (!shell.isDisposed()) {if (!display.readAndDispatch())

display.sleep();

}

}

}

则效果如下:

079aa75d5b043311d458b8e7f50eb420.png

2.参数: horizontalSpan

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

代码:

public classLBMShow{public static voidmain(String args[]){final Display display=Display.getDefault();final Shell shell=newShell(display);

shell.setText(“Hello”);

GridLayout gridLayout=new GridLayout(2, true);

GridData gridData=newGridData();

gridData.horizontalSpan=2;

shell.setLayout(gridLayout);final Label nameLabel=newLabel(shell, SWT.BORDER);

nameLabel.setText(“name: “);final Text nameText=newText(shell, SWT.BORDER);

nameText.setText(“1”);

nameLabel.setLayoutData(gridData);

nameText.setLayoutData(gridData);final Label passwdLabel=newLabel(shell, SWT.BORDER);

passwdLabel.setText(“password: “);final Text passwdText=newText(shell, SWT.BORDER);

passwdText.setText(“2”);final Button button = newButton(shell, SWT.NONE);

button.setText(“登录”);//button.setBounds(32, 28, 58, 22);

shell.open();//shell.layout();//消息循环

while (!shell.isDisposed()) {if (!display.readAndDispatch())

display.sleep();

}

}

}

效果;

5de2c43cbc38f316d99cffe55767fe5d.png

3.参数: grabExcessHorizontalSpace

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

代码:

public classLBMShow{public static voidmain(String args[]){final Display display=Display.getDefault();final Shell shell=newShell(display);

shell.setText(“Hello”);

GridLayout gridLayout=new GridLayout(2, true);

GridData gridData=newGridData();

gridData.grabExcessHorizontalSpace=true;

shell.setLayout(gridLayout);final Label nameLabel=newLabel(shell, SWT.BORDER);

nameLabel.setText(“name: “);final Text nameText=newText(shell, SWT.BORDER);

nameText.setText(“1”);

nameLabel.setLayoutData(gridData);

nameText.setLayoutData(gridData);final Label passwdLabel=newLabel(shell, SWT.BORDER);

passwdLabel.setText(“password: “);final Text passwdText=newText(shell, SWT.BORDER);

passwdText.setText(“2”);final Button button = newButton(shell, SWT.NONE);

button.setText(“登录”);//button.setBounds(32, 28, 58, 22);

shell.open();//shell.layout();//消息循环

while (!shell.isDisposed()) {if (!display.readAndDispatch())

display.sleep();

}

}

}

效果:

1538c08cf7c7e423709f31570de481e5.png

4. 参数: grabExcessVerticalSpace

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

代码:

public classLBMShow{public static voidmain(String args[]){final Display display=Display.getDefault();final Shell shell=newShell(display);

shell.setText(“Hello”);

GridLayout gridLayout=new GridLayout(2, true);

GridData gridData=newGridData();

gridData.grabExcessVerticalSpace=true;

shell.setLayout(gridLayout);final Label nameLabel=newLabel(shell, SWT.BORDER);

nameLabel.setText(“name: “);final Text nameText=newText(shell, SWT.BORDER);

nameText.setText(“1”);

nameLabel.setLayoutData(gridData);

nameText.setLayoutData(gridData);final Label passwdLabel=newLabel(shell, SWT.BORDER);

passwdLabel.setText(“password: “);final Text passwdText=newText(shell, SWT.BORDER);

passwdText.setText(“2”);final Button button = newButton(shell, SWT.NONE);

button.setText(“登录”);//button.setBounds(32, 28, 58, 22);

shell.open();//shell.layout();//消息循环

while (!shell.isDisposed()) {if (!display.readAndDispatch())

display.sleep();

}

}

}

效果:

7015f7a1cf25f8fbf4d494e4f012e0c0.png

5.参数: widthHint

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

代码;

public classLBMShow{public static voidmain(String args[]){final Display display=Display.getDefault();final Shell shell=newShell(display);

shell.setText(“Hello”);

GridLayout gridLayout=new GridLayout(2, true);

GridData gridData=newGridData();

gridData.widthHint=500;

shell.setLayout(gridLayout);final Label nameLabel=newLabel(shell, SWT.BORDER);

nameLabel.setText(“name: “);final Text nameText=newText(shell, SWT.BORDER);

nameText.setText(“1”);

nameLabel.setLayoutData(gridData);

nameText.setLayoutData(gridData);final Label passwdLabel=newLabel(shell, SWT.BORDER);

passwdLabel.setText(“password: “);final Text passwdText=newText(shell, SWT.BORDER);

passwdText.setText(“2”);final Button button = newButton(shell, SWT.NONE);

button.setText(“登录”);//button.setBounds(32, 28, 58, 22);

shell.open();//shell.layout();//消息循环

while (!shell.isDisposed()) {if (!display.readAndDispatch())

display.sleep();

}

}

}

效果:

6f3e92ca7a39deb8d50bb74c8ea448a3.png

6.参数: heightHint

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

代码:

public classLBMShow{public static voidmain(String args[]){final Display display=Display.getDefault();final Shell shell=newShell(display);

shell.setText(“Hello”);

GridLayout gridLayout=new GridLayout(2, true);

GridData gridData=newGridData();

gridData.heightHint=500;

shell.setLayout(gridLayout);final Label nameLabel=newLabel(shell, SWT.BORDER);

nameLabel.setText(“name: “);final Text nameText=newText(shell, SWT.BORDER);

nameText.setText(“1”);

nameLabel.setLayoutData(gridData);

nameText.setLayoutData(gridData);final Label passwdLabel=newLabel(shell, SWT.BORDER);

passwdLabel.setText(“password: “);final Text passwdText=newText(shell, SWT.BORDER);

passwdText.setText(“2”);final Button button = newButton(shell, SWT.NONE);

button.setText(“登录”);//button.setBounds(32, 28, 58, 22);

shell.open();//shell.layout();//消息循环

while (!shell.isDisposed()) {if (!display.readAndDispatch())

display.sleep();

}

}

}

效果:

013d7bc9cc0395eaebe7a1e99efc7b46.png

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/141143.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号