Search code examples
eclipseuser-interfaceautoresizee4

Eclipse e4: creating a 3 part window trim without resizing text in tool control


I created a Window Trim - Top

now I add 3 Tool Control

first only should contain a SWT-Text and not resize ever...

however, when I type some text and resize my window, it automatically resizes the SWT-Text to fit the text, which it should not.

So how can I give that Tool Control, or the Composite, or the Text the right Size and tell it, NOT to resize!?

public class TrimBarSearch {

@Inject
ISearchService searchService;

private Text txtSearch;
private Composite composite;

@Inject
public TrimBarSearch() {

}

@PostConstruct
public void createGui(final Composite parent) {

    parent.setLayoutData(new GridLayout(3, false));
    composite = new Composite(parent, SWT.NONE);

    Point xy = new Point(300, 15);
    Point sizeComposite = new Point(310, 25);

    composite.setLayout(new GridLayout(1, false));
    composite.setSize(sizeComposite);
    txtSearch = new Text(composite, SWT.FILL);
    txtSearch.setSize(xy);
    txtSearch.setText("");

    // TODO fix resizing-problem 
    parent.getShell().addListener(SWT.Resize, e -> {
        //maybe here?!
    });}

Solution

  • Never try and mix Layouts with setSize - it does not work, the layout will override your size.

    Instead you can specify a width hint for the text in the GridData for the text. Instead of:

    txtSearch.setSize(xy);
    

    use:

    GridData data = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
    data.widthHint = 300;
    txtSize.setLayoutData(data);