使用 shell 调整 table 大小并对齐按钮?
Resizing table with shell and aligning buttons?
如果我拖动 shell 的边框,谁能告诉我如何调整 table 的大小。换句话说,我希望我的 table 端连接到 shell,这样如果 shell 正在调整大小,table 也会随之调整。我也有按钮的问题。我需要将它们定位在右下角,在 table 下方,但是我为对齐设置了什么(GridData.HORIZONTAL_ALIGN_BEGINNING 或 new GridData(SWT.END, SWT.END, false, false) 或 new GridData(SWT.END, SWT.BOTTOM, false, false) 它与输出完全相同)它将我的两个按钮设置在左下角,一个设置在右下角。这是 table:
的代码和图片
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);
左侧 2 个按钮,右侧 1 个。
编辑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);
按钮的结果相同。
布局使用 4 列:
final GridLayout layout1 = new GridLayout(4, false);
并使用空填充标签抓住按钮左侧的 space:
Label filler = new Label(composite, SWT.LEAD);
filler.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
GridData gridData2 = new GridData(SWT.END, SWT.END, false, false);
gridData2.widthHint = 80;
Button buttonOk = new Button(composite, SWT.PUSH | SWT.CENTER);
buttonOk.setText("OK");
buttonOk.setLayoutData(gridData2);
gridData2 = new GridData(SWT.END, SWT.END, false, false);
gridData2.widthHint = 80;
Button buttonCancel = new Button(composite, SWT.PUSH | SWT.CENTER);
buttonCancel.setText("Cancel");
buttonCancel.setLayoutData(gridData2);
gridData2 = new GridData(SWT.END, SWT.END, false, false);
gridData2.widthHint = 80;
Button buttonHelp = new Button(composite, SWT.PUSH | SWT.CENTER);
buttonHelp.setText("Help");
buttonHelp.setLayoutData(gridData2);
如果我拖动 shell 的边框,谁能告诉我如何调整 table 的大小。换句话说,我希望我的 table 端连接到 shell,这样如果 shell 正在调整大小,table 也会随之调整。我也有按钮的问题。我需要将它们定位在右下角,在 table 下方,但是我为对齐设置了什么(GridData.HORIZONTAL_ALIGN_BEGINNING 或 new GridData(SWT.END, SWT.END, false, false) 或 new GridData(SWT.END, SWT.BOTTOM, false, false) 它与输出完全相同)它将我的两个按钮设置在左下角,一个设置在右下角。这是 table:
的代码和图片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);
按钮的结果相同。
布局使用 4 列:
final GridLayout layout1 = new GridLayout(4, false);
并使用空填充标签抓住按钮左侧的 space:
Label filler = new Label(composite, SWT.LEAD);
filler.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
GridData gridData2 = new GridData(SWT.END, SWT.END, false, false);
gridData2.widthHint = 80;
Button buttonOk = new Button(composite, SWT.PUSH | SWT.CENTER);
buttonOk.setText("OK");
buttonOk.setLayoutData(gridData2);
gridData2 = new GridData(SWT.END, SWT.END, false, false);
gridData2.widthHint = 80;
Button buttonCancel = new Button(composite, SWT.PUSH | SWT.CENTER);
buttonCancel.setText("Cancel");
buttonCancel.setLayoutData(gridData2);
gridData2 = new GridData(SWT.END, SWT.END, false, false);
gridData2.widthHint = 80;
Button buttonHelp = new Button(composite, SWT.PUSH | SWT.CENTER);
buttonHelp.setText("Help");
buttonHelp.setLayoutData(gridData2);