2012-10-19 30 views
4

所以我創建一個圖像放置在標題區域。除了僅顯示1/4的圖像之外,一切都有效?TitleAreaDialog - 調整標題圖像

我的形象其實是文本和圖像中的一個圖像進行合成EX:JKTeater [] < - 圖標 所以現在只有JKT是顯示在標題區域

這裏是create()方法

public void create() { 
    super.create(); 
    setTitle("JKTeater Application"); 
    setMessage("Hello World"); 
    if (image != null) setTitleImage(image); 

} 
  1. 是否存在標題區域代碼允許的特定尺寸?
  2. 有沒有辦法將圖像的末尾放在標題區域的末尾?
  3. 你可以使用佈局來移動它嗎?
  4. 如何在標題區域底部獲得黑色水平線?

編輯

enter image description here

我相信,它會問得多,看看是否你實際上可以從基本的顏色改變背景顏色的漸變

+0

好的,你的圖像沒有完整顯示?你可以上傳圖片嗎? – Baz

回答

3

以下是一個示例TitleAreaDialog。正如你所看到的,Image完全顯示並靠右對齊:

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

    TitleAreaDialog dialog = new MyTitleAreaDialog(shell); 
    dialog.setTitleAreaColor(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND).getRGB()); 
    dialog.open(); 
} 

private static class MyTitleAreaDialog extends TitleAreaDialog 
{ 
    private Image image; 

    public MyTitleAreaDialog(Shell parentShell) { 
     super(parentShell); 
     image = new Image(Display.getDefault(), "/home/baz/Desktop/StackOverflow.png"); 
    } 

    @Override 
    public boolean close() { 
     if (image != null) 
      image.dispose(); 
     return super.close(); 
    } 

    @Override 
    protected Control createContents(Composite parent) { 
     Control contents = super.createContents(parent); 

     setTitle("Title"); 
     setMessage("Message"); 

     if (image != null) 
      setTitleImage(image); 

     return contents; 
    } 

    @Override 
    protected Control createDialogArea(Composite parent) { 
     Composite composite = (Composite) super.createDialogArea(parent); 

     // YOUR LINE HERE! 
     Label line = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL); 
     line.setLayoutData(new GridData(SWT.FILL, SWT.END, true, true)); 

     return composite; 
    } 
} 

enter image description here

是否有一個具體的大小標題區號允許?

AFAIK對尺寸沒有限制。我嘗試使用比我的屏幕分辨率大的Image,並且它已完全顯示。 Dialog顯然無法使用。

我相信,它會問得多,看看是否你實際上可以從基本的顏色改變背景顏色的漸變

背景顏色可以使用dialog.setTitleAreaColor(RGB)改變(在此大小寫背景顏色),但不能使用漸變。有一個已棄用的方法getTitleArea()這將返回標題區Composite,但我真的不會推薦使用。

如何在標題區域的底部獲得黑色的橫線?

在底部的線條是通過使用來實現:

Label line = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL); 
line.setLayoutData(new GridData(SWT.FILL, SWT.END, true, true)); 

你可以使用一個佈局移動它?

也有同樣的問題在這裏:

Moving an image of a TitleAreaDialog to the left

這些問題的答案有解釋如何改變TitleAreaDialog的細節。也許讀了他們。

+0

我會問這裏,而不是打開另一個問題。以上是偉大的!你能改變setTitle(「Hello」)的字體嗎? – jkteater