gpt4 book ai didi

java - org.eclipse.swt.widgets.Composite setSize 无法正常工作

转载 作者:行者123 更新时间:2023-12-02 01:07:49 24 4
gpt4 key购买 nike

我目前正在开发一个自定义插件,但我不太明白为什么即使存在其他 Composite 元素,Composite 元素也会占用所有空间。

我的插件执行处理程序如下:

public class IwokGeneratorHandler extends AbstractHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
Shell shell = window.getShell();
ApplicationWindow win = new ApplicationWindow(shell) {

@Override
protected Control createContents(Composite parent) {

parent.setSize(800, 600);
//first panel
Composite composite = new Composite(parent, SWT.NONE);
//x, y, width, height
composite.setBounds(10, 10, 424, 70);

//second panel
Composite composite_1 = new Composite(parent, SWT.NONE);
composite_1.setBounds(10, 86, 424, 309);

//third panel
Composite composite_2 = new Composite(parent, SWT.NONE);
composite_2.setBounds(10, 407, 424, 42);

return parent;
}
};
win.open();
return null;
}
}

但是,第一个 Composite 占据了主应用程序窗口的所有空间,而无论窗口大小如何,其他的都看不到。我检查了多次。

我是否缺少任何属性来阻止元素自动填充?

提前谢谢

最佳答案

ApplicationWindow 期望 createContents 方法返回一个包含内容中所有控件的 Composite(与大多数其他 JFace 窗口和对话框一样)类)。

所以类似:

  protected Control createContents(final Composite parent) {

parent.setSize(800, 600);

// Main body composite
Composite body = new Composite(parent, SWT.NONE);

//first panel
Composite composite = new Composite(body, SWT.NONE);
//x, y, width, height
composite.setBounds(10, 10, 424, 70);

//second panel
Composite composite_1 = new Composite(body, SWT.NONE);
composite_1.setBounds(10, 86, 424, 309);

//third panel
Composite composite_2 = new Composite(body, SWT.NONE);
composite_2.setBounds(10, 407, 424, 42);

// Return the body
return body;
}

请注意,您的代码还返回 parent,这是错误的 - 它必须是创建的复合 Material 。

注意:虽然使用 setBounds 可能看起来很简单,但如果代码在具有不同字体大小(或控制大小,如果您在 macOS/Linux/Windows 上运行)的不同计算机上运行,​​则会导致问题。强烈建议使用布局。

关于java - org.eclipse.swt.widgets.Composite setSize 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59795501/

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