编程语言
首页 > 编程语言> > java – TitleAreaDialog – 调整标题图像

java – TitleAreaDialog – 调整标题图像

作者:互联网

所以我正在创建一个放置在标题区域的图像.除了仅显示1/4的图像外,一切都有效吗?

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

这是create()方法

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

}

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

编辑

我相信,如果能够将背景颜色从基本颜色更改为渐变,那将是一个很大的问题

解决方法:

这是一个示例TitleAreaDialog.如您所见,图像完全显示并向右对齐:

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;
    }
}

Is there a specific size that the title area code allows for?

AFAIK对尺寸没有限制.我尝试使用大于我的屏幕分辨率的图像并完全显示.尽管如此,Dialog显然无法使用.

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

可以使用dialog.setTitleAreaColor(RGB)(在本例中为窗口小部件背景颜色)更改背景颜色,但不能使用渐变.有一个不推荐使用的方法getTitleArea()将返回标题区域Composite,但我真的不建议使用它.

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

底部的线是通过使用:

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?

这里有一个类似的问题:

Moving an image of a TitleAreaDialog to the left

那里的答案解释了如何更改TitleAreaDialog的细节.也许读一读.

标签:java,dialog,swt,jface,titleareadialog
来源: https://codeday.me/bug/20190629/1331106.html