gpt4 book ai didi

java - 如何在 Eclipse RCP 中使用网格布局消除组件之间的间隙?

转载 作者:行者123 更新时间:2023-12-02 05:19:16 25 4
gpt4 key购买 nike

使用网格布局我正在创建复合 Material 。但我无法缩小两种复合 Material 之间的差距。请查看图像和代码。谁能帮我解决这个问题

enter image description here

parent.setLayoutData(new GridData(GridData.FILL,GridData.CENTER, true, false, 3, 1));// whole group
GridLayout gridLayout = new GridLayout(3, false);

recurrenceGroup.setLayout(gridLayout);

radioButton1 = new Button(parent.getContent(), SWT.RADIO);
radioButton1.setText("Radio 1");
GridData gridData = GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.BEGINNING).grab(true, false).create();
radioButton1.setLayoutData(gridData);
radioButton2 = new Button(parent.getContent(), SWT.RADIO);
radioButton2.setText("Radio 2");
textBox = new Text(parent.getContent(), SWT.BORDER);
textBox.setLayoutData(new GridData(SWT.BEGINING, SWT.CENTER, true, false));
secsLabel = new Label(parent.getContent(), SWT.NONE);
secsLabel.setText("secs");

最佳答案

您可以分别使用GridLayout#horizo​​ntalSpacingGridLayout#verticalSpacing来更改子项之间的间距:

水平间距:

enter image description here

没有水平间距:

enter image description here

public static void main(String[] args)
{
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("StackOverflow");

GridLayout layout = new GridLayout(3, false);
layout.horizontalSpacing = 0;
shell.setLayout(layout);

for(int i = 0; i < 9; i++)
new Label(shell, SWT.NONE).setText("Label: " + i);

shell.pack();
shell.open();

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

关于java - 如何在 Eclipse RCP 中使用网格布局消除组件之间的间隙?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26630990/

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