user1365697
user1365697

Reputation: 6009

how to move the text to the left?

I created a toolbar with text field and two toolItem

The problem that the Text is exist in the right scrren and not in the left screen.

How I can put the text in the right screen ?

It should look :

Text item1 item2

   ToolBar treeToolBar = new ToolBar(treeComposite, SWT.RIGHT_TO_LEFT);


    Text text = new Text(treeToolBar, SWT.NONE);
    text.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, false, false));
    text.setText("Text"); 
    text.pack();

    item1 = new ToolItem(treeToolBar, SWT.PUSH | SWT.RIGHT);

    item2 = new ToolItem(treeToolBar, SWT.PUSH | SWT.RIGHT);


   treeToolBar.pack();

Upvotes: 0

Views: 655

Answers (1)

andi
andi

Reputation: 922

After you create the text, you also have to create a tab item for it. Remove the text.pack() call and insert this:

ToolItem textItem = new ToolItem(treeToolBar, SWT.SEPARATOR);
textItem.setControl(text);
textItem.setWidth(text.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);

This is how ControlContribution does in method fill(ToolBar parent, int index).

Upvotes: 1

Related Questions