gpt4 book ai didi

java - SWT Layout 重新定位表单控件

转载 作者:行者123 更新时间:2023-11-29 03:45:48 25 4
gpt4 key购买 nike

这是我的代码和表单截图。

我希望最上面的文本框占据所有可用的水平空间。
enter image description here

![Display display = new Display();][1]
Shell shell = new Shell(display);
shell.setLayout(new GridLayout());

Group group = new Group(shell, SWT.FILL);
group.setText("Group");
group.setLayout(new GridLayout(4, false));
group.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));


Label lb = new Label(group, SWT.NONE);
lb.setText("label");
new Text(group, SWT.BORDER);

Button btn = new Button(group, SWT.CHECK);
Label lbbtn = new Label(group, SWT.NONE);
lbbtn.setText("check");


Composite comp = new Composite(group, SWT.NONE);
comp.setLayout(new GridLayout(4, false));
comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
Label lb1 = new Label(comp, SWT.NONE);
lb1.setText("Text1");
Text txt = new Text(comp, SWT.BORDER);

Label lb2 = new Label(comp, SWT.NONE);
lb2.setText("Text2");
txt = new Text(comp, SWT.BORDER);

Label lb3 = new Label(comp, SWT.NONE);
lb3.setText("Text3");
txt = new Text(comp, SWT.BORDER);

Label lb4 = new Label(comp, SWT.NONE);
lb4.setText("Text4");
txt = new Text(comp, SWT.BORDER);

shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

最佳答案

使用 GridDatahorizo​​ntalSpanComposite 的值为 2,GridData值为 FILL 的 horizo​​ntalAlignmentText 小部件的 grabExcessHorizo​​ntalSpace 值为 true

我通常使用GridDataFactory创建 GridData 对象,我认为代码更清晰。

关于java - SWT Layout 重新定位表单控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10971424/

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