【发布时间】:2018-06-30 01:29:48
【问题描述】:
如果我拖动 shell 的边框,有人可以告诉我如何调整表格的大小。换句话说,我希望我的表端连接到外壳,这样如果外壳正在调整大小,表就会跟随。我也有按钮的问题。我需要将它们定位在右下角,在桌子下方,但是我为对齐设置了什么(GridData.HORIZONTAL_ALIGN_BEGINNING 或 new GridData(SWT.END, SWT.END, false, false) 或 new GridData(SWT.END, SWT.BOTTOM, false, false) 和输出一样) 它将我的两个按钮设置在左下角,一个在右下角。这是代码和表格的图片:
try {
display = new Display();
} catch (Exception ex) {
ex.printStackTrace();
}
shell = new Shell(display);
shell.setLayout(new GridLayout());
GridLayout layout = new GridLayout();
shell.setLayout(layout);
Composite composite = new Composite(shell, SWT.NONE);
// Create a composite to hold the children
GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_BOTH);
composite.setLayoutData(gridData);
// Set numColumns to 3 for the buttons
GridLayout layout1 = new GridLayout(3, false);
layout1.marginWidth = 4;
composite.setLayout(layout1);
int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL |
SWT.FULL_SELECTION | SWT.HIDE_SELECTION;
final int NUMBER_COLUMNS = 6;
table = new Table(composite, style);
GridData gridData1 = new GridData(GridData.FILL_BOTH);
gridData1.grabExcessVerticalSpace = true;
gridData1.horizontalSpan = 3;
table.setLayoutData(gridData1);
table.setLinesVisible(true);
table.setHeaderVisible(true);
String[] titles = { methodHeader, messageHeader, parametersHeader, resultHeader, deltaHeader, assertionHeader};
for (int i = 0; i < titles.length; i++) {
TableColumn column = new TableColumn(table, SWT.LEFT, i);
column.setText(titles[i]);
table.getColumn(i).pack();
}
addDataToTableModel(methodList);
GridData gridData2 = new GridData(SWT.END, SWT.END, false, false);
gridData2.widthHint = 80;
buttonOk = new Button(composite, SWT.PUSH | SWT.CENTER);
buttonOk.setText(ok);
buttonOk.setLayoutData(gridData2);
buttonCancel = new Button(composite, SWT.PUSH | SWT.CENTER);
buttonCancel.setText(cancel);
/*GridData gridData3 = new GridData(SWT.END, SWT.END, false, false);
gridData3.widthHint = 80;*/
buttonCancel.setLayoutData(gridData2);
buttonHelp = new Button(composite, SWT.PUSH | SWT.CENTER);
buttonHelp.setText(help);
/*GridData gridData4 = new GridData(SWT.END, SWT.END, false, false);
gridData4.widthHint = 80;*/
buttonHelp.setLayoutData(gridData2);
编辑1: 尝试为每个按钮使用不同的 GridData:
GridData gridData2 = new GridData(SWT.END, SWT.END, false, false);
gridData2.widthHint = 80;
buttonOk = new Button(composite, SWT.PUSH | SWT.CENTER);
buttonOk.setText(ok);
buttonOk.setLayoutData(gridData2);
buttonCancel = new Button(composite, SWT.PUSH | SWT.CENTER);
buttonCancel.setText(cancel);
GridData gridData3 = new GridData(SWT.END, SWT.END, false, false);
gridData3.widthHint = 80;
buttonCancel.setLayoutData(gridData3);
buttonHelp = new Button(composite, SWT.PUSH | SWT.CENTER);
buttonHelp.setText(help);
GridData gridData4 = new GridData(SWT.END, SWT.END, false, false);
gridData4.widthHint = 80;
buttonHelp.setLayoutData(gridData4);
按钮的结果相同。
【问题讨论】:
-
不要对多个控件重复使用
GridData- 这不起作用。每个控件都需要一个新的GridData。 -
是的,我试过这两个,结果一样:(
-
我没有说它会解决问题,我说这是错误的代码。
-
好的,谢谢,我没明白 :)