问题
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