Campa
Campa

Reputation: 4495

Add spacer in Eclipse Toolbar

I would like to add a flush-left (ragged-right) item in a toolbar of my Eclipse E4 application.

Toolbar items in Eclipse are ragged-left by default, so this is what I would like to achieve:

      toolbar
+------------------------------------------------+
| I1 |                      | I2 | I3 | ... | IN |
+------------------------------------------------+
      <-------------------->
              spacer?

Item I1 would be flush-left thanks to the effect of the spacer control in between I1 and I2 (if I got the meaning of a spacer in the first place).


I know that a stretch-tagged ToolControl in between items of a trimbar will work as a spacer; but that does not work on toolbars.

I also tried to add toolbar elements as extension points in the plugin.xml following the instructions I read from this answer. I am not sure whether this is simply not E4-compatible or if I made some mistake.

Ideas?


Likely a duplicate of How do I add a spacer to an Eclipse RCP toolbar?

Upvotes: 0

Views: 286

Answers (1)

greg-449
greg-449

Reputation: 111142

Just add a ToolControl to the Toolbar and use a class like this for the control:

public class SpacerControl
{
  public SpacerControl()
  {
    super();
  }


  @PostConstruct
  public void postConstruct(final Composite parent)
  {
    new Composite(parent, SWT.NONE)
      .setLayout(new FillLayout());
  }
}

Upvotes: 1

Related Questions