5

所以我正在创建一个图像以放置在标题区域。除了只显示图像的 1/4 之外,一切正常吗?

我的图像实际上是文本和图像组合在一个图像中 EX:JKTeater [ ] <-- 图标所以现在只有 JKT 显示在标题区域

这是 create() 方法

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

}
  1. 标题区号是否允许特定大小?
  2. 有没有办法将图像的末尾放在标题区域的末尾?
  3. 你可以使用布局来移动它吗?
  4. 如何在标题区域底部获得黑色水平线?

编辑

在此处输入图像描述

我敢肯定,如果您实际上可以将背景颜色从基本颜色更改为渐变色,这将需要很多

4

1 回答 1

5

这是一个例子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;
    }
}

在此处输入图像描述

标题区号是否允许特定大小?

AFAIK there are no restrictions to the size. I tried using an Image that was larger than my screen resolution and it was fully displayed. The Dialog was obviously unusable though.

I am sure that it would be asking to much to see if you can actually change the background color from a basic color to a gradient

The background color can be changed using dialog.setTitleAreaColor(RGB) (in this case the widget background color), but you cannot use a gradient. There is a deprecated method getTitleArea() which would return the title area Composite, but I really wouldn't recommend using that.

How can I get a black horizonal line at the bottom of the title area?

The line at the bottom was achieved by using:

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

Can you use a layout to move it around?

There is a similar question here:

Moving an image of a TitleAreaDialog to the left

那里的答案解释了如何更改TitleAreaDialog. 也许阅读他们。

于 2012-10-19T14:48:14.190 回答