Moving an image of a TitleAreaDialog to the left

≡放荡痞女 提交于 2019-12-12 12:07:44

问题


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,


回答1:


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();



回答2:


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.



来源:https://stackoverflow.com/questions/12528399/moving-an-image-of-a-titleareadialog-to-the-left

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!