[英]fonts on org.eclipse.swt.widgets.Composite are messed up on Linux
[英]org.eclipse.swt.widgets.Composite setSize not working properly
我目前正在開發一個自定義插件,我不太明白為什么一個 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
- 它必須是創建的組合。
注意:雖然使用setBounds
可能看起來很簡單,但如果代碼在具有不同字體大小的不同機器上運行(或者在 macOS/Linux/Windows 上運行時控制大小),它會導致問題。 強烈建議使用布局。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.