java - eclipse swt ExpandBar : wrong size on expand/collaps events

标签 java linux eclipse swt

我在 eclipse SWT 中有以下布局:一个 GridLayout 一列和两个 child ,一个在顶部,一个在底部。底部的是 Expandpar。当展开或折叠 ExpandBar 时,应更新两个子项的大小。这是代码:

package tests.julia.layout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.ExpandBar;
import org.eclipse.swt.widgets.ExpandItem;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class MyLayoutExpandBar {
    public static void main (String [] args) {
        final Display display = new Display ();
        Shell shell = new Shell (display);
        shell.setLayout (new FillLayout());

        final Composite parent = new Composite (shell, SWT.BORDER);
        parent.setLayout(new GridLayout());

        Composite comp = new Composite(parent, SWT.BORDER);
        comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

        final ExpandBar expandBar = new ExpandBar (parent, SWT.V_SCROLL);
        expandBar.setLayoutData(new GridData(SWT.FILL, SWT.END, true, false));

        ExpandItem item = new ExpandItem (expandBar, SWT.NONE);
        item.setText("Expand Item");
        item.setHeight(200);
        item.setExpanded(true);

        Group group = new Group(expandBar, SWT.NONE);
        group.setText("Item Content");
        item.setControl(group);


        /* Listener */
        expandBar.addListener(SWT.Expand, new Listener() {

            @Override
            public void handleEvent(Event event) {
                display.asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        System.out.println("Expand: " + expandBar.getSize());
                        parent.layout();
                        System.out.println("Expand: " + expandBar.getSize());
                    }
                });
            }
        });
        expandBar.addListener(SWT.Collapse, new Listener() {

            @Override
            public void handleEvent(Event event) {
                display.asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        System.out.println("Collapse: " + expandBar.getSize());
                        parent.layout();
                        System.out.println("Collapse: " + expandBar.getSize());
                    }
                });
            }
        });
        shell.setText("Shell");
        shell.setSize(300, 300);
        shell.open ();

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

这在 Windows 下工作正常,但在 Linux 下,ExpandBar 的大小在展开时很小,在折叠时很大,因此与它应该的大小相反。当 Shell 调整大小时(通过拖动其边框),ExpandBar 的大小将变得正确。

有谁知道如何做到这一点?

谢谢, Julia

最佳答案

这件事很可能是 Ubuntu 独有的错误。 查看此错误报告 https://bugs.eclipse.org/bugs/show_bug.cgi?id=532546

关于java - eclipse swt ExpandBar : wrong size on expand/collaps events,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49304422/

相关文章:

java - 数字键盘显示不正确

java - 将 vector 、序列和映射从 Clojure 返回到 Java

android - 请问这个渲染库版本比你eclipse中的ADT插件版本更新怎么办?

c++ - 将文本文件读入双向链表并输出 - C++

java - 通过用户输入在java中打印一系列数字

java - 我应该如何为以下场景设计方法签名

linux - ansible中的bash数组元素计数操作

linux - 如何在 Linux 中设置目录大小限制?

linux - 如何在gui中转换 Asterisk ?

java - Eclipse 中的枚举 nosuchmethoderror