TitleAreaDialog - 调整标题图像

时间:2012-10-19 13:59:49

标签: java dialog swt jface titleareadialog

所以我创建了一个放置在标题区域的图像。除了仅显示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. 如何在标题区底部获得黑色水平线?
  5. 修改

    enter image description here

    我确信要问你是否可以将背景颜色从基本颜色改为渐变

1 个答案:

答案 0 :(得分: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的详细信息。也许读一读。