Java 如何在SWT中扩展组件布局?
我创建了一个包含两部分的应用程序:Java 如何在SWT中扩展组件布局?,java,swt,Java,Swt,我创建了一个包含两部分的应用程序: 1. tree viewer 2. table viewer + messages 看起来像 ------------------------------- - tree - table - - - - -
1. tree viewer
2. table viewer + messages
看起来像
-------------------------------
- tree - table -
- - -
- - -----------------
- - -
- - messages -
-------------------------------
问题是正确的部分(表和消息不像第一部分那样一直延伸到末尾)
看起来像
-------------------------------
- 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();
}
看起来像这样:
如果这不是您想要的,请使用更多详细信息/代码更新您的问题。但我添加了ridata detailsridata=new GridData();detailsGridData.horizontalAlignment=SWT.FILL;detailsGridData.grabExcessHorizontalSpace=true;detailsGridData.verticalAlignment=SWT.FILL;detailsGridData.grabExcessVerticalSpace=true;detailsComposite.setLayoutData(detailsGridData)@user1365697更新了我的答案。@user1365697当然,更新了答案。看起来是一样的。嗨,巴兹,我们可以聊一聊吗?我更新了我的代码,通常在右侧屏幕上,拆分为树,消息有两个不同的组合(它们有相同的父项)。问题是,我在版面中看不到任何消息,版面的大小与左侧屏幕的大小不一样。我希望该表将捕获几乎所有屏幕,并且消息只能显示一行