SWT 控件拒绝“占用多余的垂直空间”

发布于 2024-11-17 11:05:21 字数 2637 浏览 10 评论 0原文

情况是,TopTaskGroup(左一个)可以在调整窗口大小时“抓住多余的垂直空间”在此处输入图像描述,但是NewTaskGroup(右侧),在其上添加 TooBar 后(请参阅 createAddBtnOnGroup 方法),它不会随着您调整窗口大小而增长。这是为什么?

(我有一个带有 2 列 GridLayout 的 shell 实例)

在此处输入图像描述

代码在这里:

private void createTaskWidgets() {
    createTopTaskGroup();
    createNewTaskGroup();
}

private void createTopTaskGroup() {
    Group topTasksGroup = new Group(shell, SWT.SHADOW_NONE);
    topTasksGroup.setText(TaskConsts.TOP_TASK_LIST);

    topTasksTable = new TaskTable(topTasksGroup, TaskTable.SORT_BY_VOTES, iteration, this);
    topTasksTable.setLayoutData(getTableGridData() );

    topTasksGroup.setLayout(new GridLayout() );
    topTasksGroup.setLayoutData(getTableGridData() );
    topTasksGroup.pack();
}

private void createNewTaskGroup() {
    Group newTasksGroup = new Group(shell, SWT.SHADOW_NONE);
    newTasksGroup.setText(TaskConsts.NEW_TASK_LIST);

    newTasksTable = new TaskTable(newTasksGroup, TaskTable.SORT_BY_CREATION_TIME, iteration, this);
    topTasksTable.setLayoutData(getTableGridData() );

    ToolBar actionToolBar = createAddBtnOnGroup(newTasksGroup);

    newTasksGroup.setLayout(new GridLayout() );
    newTasksGroup.setLayoutData(getTableGridData() );
    newTasksGroup.layout();
    newTasksGroup.pack();

    // set actionToolBar's location to newTasksGroup's right-top position
    actionToolBar.setLocation(
            newTasksGroup.getLocation().x + newTasksGroup.getSize().x
                    - actionToolBar.getSize().x - 5,
            newTasksGroup.getLocation().y - 2);
}

private GridData getTableGridData() {
    GridData gridData = new GridData(0, SWT.FILL, false, true);
    return gridData;
}

private ToolBar createAddBtnOnGroup(Group newTasksGroup) {
    ToolBar actionToolBar = new ToolBar(newTasksGroup, SWT.HORIZONTAL | SWT.RIGHT);

    addTaskToolItem = new ToolItem(actionToolBar, SWT.PUSH | SWT.RIGHT);
    addTaskToolItem.setImage(new Image(display, TaskConsts.ICON_PLUS));

    final MainWindow mainWindow = this;
    addTaskToolItem.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            new CreateTask(getShell(), mainWindow);
        }
    });

    GridData gridData = new GridData();
    gridData.exclude = true;
    actionToolBar.setLayoutData(gridData);

    actionToolBar.pack();

    return actionToolBar;
}

private void organize() {
    GridLayout gridLayout = new GridLayout(2, false);
    shell.setLayout(gridLayout);
    shell.pack();
}

提前致谢~

The case is that the TopTaskGroup(left one) can "grab excess vertical space" while resizing windowenter image description here, but the NewTaskGroup(the right one), after adding a TooBar on it(see the createAddBtnOnGroup method), it doesn't grow as you resize the window. Why is that?

(I have a shell instance with 2-column GridLayout)

enter image description here

Code is here:

private void createTaskWidgets() {
    createTopTaskGroup();
    createNewTaskGroup();
}

private void createTopTaskGroup() {
    Group topTasksGroup = new Group(shell, SWT.SHADOW_NONE);
    topTasksGroup.setText(TaskConsts.TOP_TASK_LIST);

    topTasksTable = new TaskTable(topTasksGroup, TaskTable.SORT_BY_VOTES, iteration, this);
    topTasksTable.setLayoutData(getTableGridData() );

    topTasksGroup.setLayout(new GridLayout() );
    topTasksGroup.setLayoutData(getTableGridData() );
    topTasksGroup.pack();
}

private void createNewTaskGroup() {
    Group newTasksGroup = new Group(shell, SWT.SHADOW_NONE);
    newTasksGroup.setText(TaskConsts.NEW_TASK_LIST);

    newTasksTable = new TaskTable(newTasksGroup, TaskTable.SORT_BY_CREATION_TIME, iteration, this);
    topTasksTable.setLayoutData(getTableGridData() );

    ToolBar actionToolBar = createAddBtnOnGroup(newTasksGroup);

    newTasksGroup.setLayout(new GridLayout() );
    newTasksGroup.setLayoutData(getTableGridData() );
    newTasksGroup.layout();
    newTasksGroup.pack();

    // set actionToolBar's location to newTasksGroup's right-top position
    actionToolBar.setLocation(
            newTasksGroup.getLocation().x + newTasksGroup.getSize().x
                    - actionToolBar.getSize().x - 5,
            newTasksGroup.getLocation().y - 2);
}

private GridData getTableGridData() {
    GridData gridData = new GridData(0, SWT.FILL, false, true);
    return gridData;
}

private ToolBar createAddBtnOnGroup(Group newTasksGroup) {
    ToolBar actionToolBar = new ToolBar(newTasksGroup, SWT.HORIZONTAL | SWT.RIGHT);

    addTaskToolItem = new ToolItem(actionToolBar, SWT.PUSH | SWT.RIGHT);
    addTaskToolItem.setImage(new Image(display, TaskConsts.ICON_PLUS));

    final MainWindow mainWindow = this;
    addTaskToolItem.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            new CreateTask(getShell(), mainWindow);
        }
    });

    GridData gridData = new GridData();
    gridData.exclude = true;
    actionToolBar.setLayoutData(gridData);

    actionToolBar.pack();

    return actionToolBar;
}

private void organize() {
    GridLayout gridLayout = new GridLayout(2, false);
    shell.setLayout(gridLayout);
    shell.pack();
}

Thanks in advance~

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坏尐絯℡ 2024-11-24 11:05:21

感谢您出色的问题描述!

在我看来,这是一个简单的复制粘贴错误。

createNewTaskGroup 方法中的第四行不应该

topTasksTable.setLayoutData(getTableGridData() );

newTasksTable.setLayoutData(getTableGridData() );

Thanks for your excellent problem description!

It seems to me that this is a simple copy-paste bug.

The fourth line in your createNewTaskGroup method should not be

topTasksTable.setLayoutData(getTableGridData() );

but

newTasksTable.setLayoutData(getTableGridData() );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文