How the heck do I center something in SWT??

Today I’ve helped a co-worker a bit with centering something on an Eclipse view. Some nasty stuff with padding Composites and such.

To center one control on a view we actually added 3 extra empty composites to push things to the right spot. This got to be easier to do.

Suggestions are very welcome.

4 Replies to “How the heck do I center something in SWT??”

  1. Well, that constructor does not exist. But GridData.CENTER does. I’ll have to try if it works. I’m not sure, but I do think I tried it with this.

    I didn’t mention that the control that has to be centered is a toolbar filled with actions by contribution items. It does complicate things a bit. šŸ˜‰

  2. The constructor does exist, I use it all the time: GridData API docs. GridData.CENTER is just a deprecated alternative for SWT.CENTER.

    If the toolbar is filled by contribution items at createControl time this should not be any different from a statically filled toolbar. If it is filled dynamically it’s still not a big deal: just call layout() on the parent element after you altered the toolbar items to re-align the control.

  3. Note to self, plan a visit to the optician.

    You’re right, I did take a look at the API docs. It’s beyond me why I didn’t see it for myself. lol

Comments are closed.