0
votes

I am trying to put a GraphicalEditor into a GridLayout in an eclipse RCP project in order to add another textfield below it.

The problem is: When I do so, the Editor will not fit into its window automatically anymore despite setting its surrounding forms GridData object to grabExcessiveHorizontal(Vertical)Space = true(should expand its grid cell as wide as possible) as well as horizontal/verticalAlignment = SWT.FILL(should fill the editor in its cell as wide as possible). The editor will then have a fixed size and will not scale with its window any more, which I dont want.

I used the GEF example from this tutorial:

https://www.inf.ed.ac.uk/teaching/courses/ip/resources/GEF/GEF_Tutorial_2up.pdf

I modified the code from the tutorial trying to set the layout in method createPartControl(Composite parent) in the following manner...

@Override
public void createPartControl(Composite parent){

    FormToolkit toolkit = new FormToolkit(parent.getDisplay());
    Form form = toolkit.createForm(parent);
    Composite body = form.getBody();

    //FillLayout fillLayout = new FillLayout();
    //fillLayout.marginHeight = 15;
    //fillLayout.marginWidth = 15;

    GridLayout formLayout = new GridLayout();
    formLayout.marginHeight = 15;
    formLayout.marginWidth = 15;

    GridData formData = new GridData(SWT.FILL,SWT.FILL, true, true);

    body.setLayout(formLayout);
    body.setLayoutData(formData);
    body.setBackground(new Color(parent.getDisplay(),255,0,0));

    super.createPartControl(body);
}

...producing the following(i colored the body of the form for better visibility of the problem):

http://g10vz.de/files/graphicaleditorgridlayout.png

Why does the editor not fit in the form ? Or did i made a mistake in my expectation of the behavior of SWTs GridLayout ? When a FillLayout is used, as shown in the commented out lines, the editor is behaving as desired.

Greetings

1
The GridData must be set on the children of the Composite using GridLayout - presumably they are created in super.createPartControl(body)greg-449

1 Answers

0
votes

@greg-449 thank you! your suggestion brougt me to this solution:

(...)
super.createPartControl(body);

getGraphicalControl().getParent().setLayoutData(formData);

Greetings :)