Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TitleAreaDialog - adjusting the title image

So I am creating a image to place in the title area. Everything works with the exception that only a 1/4th of the image is displayed?

my image is actually text and a image combine in one image EX: JKTeater [ ] <-- icon so right now only JKT is showing in the title area

Here is the create() method

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

}
  1. Is there a specific size that the title area code allows for?
  2. Is there a way to place the end of the image at the end of the title area?
  3. Can you use a layout to move it around?
  4. How can I get a black horizonal line at the bottom of the title area?

EDIT

enter image description here

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

like image 852
jkteater Avatar asked Oct 19 '12 13:10

jkteater


1 Answers

Here is an example TitleAreaDialog. As you can see, the Image is completely shown and aligned to the right:

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

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

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

The answers there explain how to change details of the TitleAreaDialog. Maybe read up on them.

like image 180
Baz Avatar answered Oct 12 '22 07:10

Baz