Moving an image of a TitleAreaDialog to the left

2019-06-24 02:12发布

I'm working on a SWT/Jface project based on Java SE, i want to move the image of a TitleAreaDialog to the left. is it possible ? if not is there anyway ?

Thanks,

2条回答
做个烂人
2楼-- · 2019-06-24 02:58

There is no way to configure it using API, the layout is hard-coded. One way is to hack into the dialog controls and change their layout data, but it is likely easier to implement your own class (using TitleAreaDialog as an example).

If you subclass TitleAreaDialog you have to override createContents(Composite) method, otherwise the TitleAreaDialog will create its own title area by calling createTitleArea(). I suggest that at first you just copy the code from TitleAreaDialog.createContents() and start replacing stuff that you need to be done differently. I don't know exactly what needs to be done without actually doing everything.

查看更多
\"骚年 ilove
3楼-- · 2019-06-24 03:17

You can modify the layout data of the image label as follows:

    TitleAreaDialog tad = new TitleAreaDialog(getShell()) {

        @Override
        protected Control createContents(Composite parent) {
            Control control = super.createContents(parent);
            Label label = getTitleImageLabel();
            FormData data = (FormData) label.getLayoutData();
            data.left = new FormAttachment(0, 0);
            data.right = null;
            return control;
        }

    };
    tad.setTitle("title");
    tad.setTitleImage(Activator.imageDescriptorFromPlugin(
            Activator.PLUGIN_ID, "image.gif").createImage());
    tad.open();
查看更多
登录 后发表回答