gpt4 book ai didi

java - 使用 shell 和对齐按钮调整表的大小?

转载 作者:行者123 更新时间:2023-11-29 04:17:57 25 4
gpt4 key购买 nike

如果我拖动 shell 的边框,有人能告诉我如何调整表格的大小吗?换句话说,我希望我的表端连接到 shell,这样如果正在调整 shell 的大小,表就会跟随。我也有按钮的问题。我需要将它们定位在右下角,在 table 下面,但是我为对齐设置了什么(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);

This is how my frame looks when I run this code左侧 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);

并使用一个空的填充标签来捕获按钮左侧的空间:

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

关于java - 使用 shell 和对齐按钮调整表的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51102577/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com