gpt4 book ai didi

java - 如何在SWT中拉伸(stretch)复合布局?

转载 作者:行者123 更新时间:2023-12-01 13:43:21 27 4
gpt4 key购买 nike

我创建了一个包含两部分的应用程序:

      1. tree viewer
2. table viewer + messages

看起来像

                 -------------------------------
- tree - table -
- - -
- - -----------------
- - -
- - messages -
-------------------------------

右侧部分(表格和消息不会像第一部分一样拉伸(stretch)到最后)的问题

看起来像

                  -------------------------------
- tree - table -
- - ----------------- -
- - -
meesages -
- --------------------
- -
-------------

这是代码

     SashForm sashForm = new SashForm(parent, SWT.HORIZONTAL);
Composite treeComposite = new Composite(sashForm, SWT.BORDER);
Composite detailsCompositePart = new Composite(sashForm, SWT.NONE);

GridLayout detailsGridLayout = new GridLayout();
detailsGridLayout.numColumns = 1;
detailsCompositePart.setLayout(detailsGridLayout);

GridData detailsPartGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
detailsCompositePart.setLayoutData(detailsPartGridData);

detailsComposite = new Composite(detailsCompositePart, SWT.BORDER);
GridLayout detailsSideGridLayout = new GridLayout();
detailsSideGridLayout.numColumns = 1;
detailsComposite.setLayout(detailsSideGridLayout);
GridData detailsGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
detailsComposite.setLayoutData(detailsGridData);

messageComposite = new Composite(detailsComposite, SWT.NONE);

GridLayout messageGridLayout = new GridLayout();
messageGridLayout.numColumns = 1;
messageComposite.setLayout(messageGridLayout);
GridData messageGridData = new GridData(SWT.FILL, SWT.END, true, false);
messageComposite.setLayoutData(messageGridData);



labelError = new Label(messageGridData , SWT.NONE);
GridData data = new GridData(SWT.FILL, SWT.END, true, false);
data.heightHint = 30;
labelError.setLayoutData(data);
//labelError.setText("Message!!!!!!!!!!!!!!"); //$NON-NLS-1$

最佳答案

如果没有完整的代码,很难判断发生了什么。

下面是一些可以帮助您的代码:

public static void main(String[] args)
{
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, false));
shell.setText("StackOverflow");

Composite horizontal = new Composite(shell, SWT.NONE);
horizontal.setLayout(new GridLayout(2, false));
horizontal.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

Composite left = new Composite(horizontal, SWT.BORDER);
left.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

Composite right = new Composite(horizontal, SWT.NONE);
GridLayout layout = new GridLayout(1, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
right.setLayout(layout);
right.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

Composite top = new Composite(right, SWT.BORDER);
top.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

Composite bottom = new Composite(right, SWT.BORDER);
bottom.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

shell.pack();
shell.setSize(600, 400);
shell.open();

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

display.dispose();
}

看起来像这样:

enter image description here

如果这不是您要查找的内容,请使用更多详细信息/代码更新您的问题。

关于java - 如何在SWT中拉伸(stretch)复合布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20522564/

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