gpt4 book ai didi

java - 让 FillLayout 表现正确

转载 作者:行者123 更新时间:2023-12-01 12:51:38 25 4
gpt4 key购买 nike

我正在尝试创建一个包含两棵树的 View ,它们占据整个显示屏。截至目前,这两棵树只占据了 Canvas 的一半(左半部分)。我不明白为什么,因为我尝试了发送到每个设置方法的许多不同参数,例如 setLayout、SashForm 等。这是我的代码,我附加了一张图像来显示我现在得到的简化 View 是。

    super(parent);
setDisplayName("Viewer");
setLayout(new FillLayout());
((FillLayout) getLayout()).marginHeight = ((FillLayout) getLayout()).marginWidth = 20;

fullForm = new SashForm(this, SWT.VERTICAL);
fullForm.setLayout(new FillLayout());

adForm = new SashForm(fullForm, SWT.VERTICAL);
adForm.setLayout(new FillLayout());

countLabel = GUIToolkit.newLabel(this, SWT.CENTER, "", new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
countLabel.setFont(boldFont);

ad1Tree = createTree(fullForm, "name1", "col1", "col2");
ad2Tree = createTree(fullForm, "name2", "col1", "col2");

创建树

    private static Tree createTree(final Composite parent, final String text, final String... columns) {
final Composite group = GUIToolkit.newGroup(parent, SWT.NONE, text, null);
group.setFont(FontManager.NORMAL_BOLD);
group.setLayout(new FillLayout());
final Tree tree = new Tree(group, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
tree.setHeaderVisible(true);
GUIToolkit.createColumns(tree, columns);
GUIToolkit.addColumnSort(tree, DATA);
GUIToolkit.removeDoubleClickExpand(tree);

This is what the view looks like in a very simplified manner

最佳答案

我认为你的问题是你没有分配 GridDataGroup包含TreeTree本身。

尝试像这样更新您的代码:

private static Tree createTree(final Composite parent, final String text, final String... columns) {
final Composite group = GUIToolkit.newGroup(parent, SWT.NONE, text, new GridData(SWT.FILL, SWT.FILL, true, true)); // <-- THIS
group.setFont(FontManager.NORMAL_BOLD);
group.setLayout(new FillLayout());
final Tree tree = new Tree(group, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); // <-- THIS
tree.setHeaderVisible(true);
GUIToolkit.createColumns(tree, columns);
GUIToolkit.addColumnSort(tree, DATA);
GUIToolkit.removeDoubleClickExpand(tree);
}

不确定到底是什么 GUIToolkit是,但我假设它只会应用 LayoutData您提供。

<小时/>

更新:

好吧,我就是这样做的:

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

Group top = new Group(shell, SWT.NONE);
top.setLayout(new GridLayout(1, false));
top.setText("Top");
top.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

Group bottom = new Group(shell, SWT.NONE);
bottom.setLayout(new GridLayout(1, false));
bottom.setText("Bottom");
bottom.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

Tree topTree = new Tree(top, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
createColumns(topTree);
Tree bottomTree = new Tree(bottom, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
createColumns(bottomTree);

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

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

private static void createColumns(Tree tree)
{
tree.setHeaderVisible(true);

for(int i = 0; i < 3; i++)
new TreeColumn(tree, SWT.NONE).setText("Col " + i);

for(int i = 0; i < 10; i++)
{
TreeItem item = new TreeItem(tree, SWT.NONE);

for(int j = 0; j < tree.getColumnCount(); j++)
{
item.setText(j, "Item " + i + " " + j);
}
}

for(int i = 0; i < tree.getColumnCount(); i++)
tree.getColumn(i).pack();
}

关于java - 让 FillLayout 表现正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24186246/

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