未設置邊界,我的標籤未按預期在下面的代碼中顯示。 我在shell中創建一個Composite,因爲我只想讓背景圖像出現在這個組合中。未在合成內顯示Eclipse SWT標籤
在這種情況下,該綁定應該是什麼?我可以根據標籤的文字獲得最佳範圍嗎?
Display display = PlatformUI.createDisplay();
Shell shell = new Shell(display);
shell.setText("Header);
Composite main = new Composite(shell, SWT.NONE);
main.setBounds(10, 5, 775, 505);
InputStream is = getClass().getResourceAsStream("/resources/bg.png");
Image bg = new Image(display, is);
main.setBackgroundImage(bg);
main.setBackgroundMode(SWT.INHERIT_DEFAULT);
Label label = new Label(main, SWT.NONE);
//label.setBounds(0, 0, 400,100); // not showing if commented away
label.setText("Label 1");
你嘗試'main.pack()'或'shell.pack()'? – Baz 2012-07-19 08:58:22
此外,你似乎並沒有使用佈局。有關概覽,請參閱http://www.eclipse.org/articles/article.php?file=Article-Understanding-Layouts/index.html。 – Baz 2012-07-19 09:08:16
我以爲我在默認的GridLayout的地方閱讀它。糾正我,如果我錯了。 – humansg 2012-07-19 10:08:15