gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:17:16 32 4
gpt4 key购买 nike

我在 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/

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