Macs, Java, software development, IT related books and things I do for a living.
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.
| Print article | This entry was posted by Jeroen on July 27, 2006 18:38 at 18:38, and is filed under Eclipse, Java, Work. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 4 years ago
control.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true)); ?
about 4 years ago
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.
about 4 years ago
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.
about 4 years ago
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