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

2022-09-01 16:45:47 浏览数 (1)

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

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();

}

}

}

则效果如下:

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();

}

}

}

效果;

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();

}

}

}

效果:

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();

}

}

}

效果:

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();

}

}

}

效果:

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();

}

}

}

效果:

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

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

0 人点赞