[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] Re: Labels in ToolBars
|
Hi Dave,
I think the only way to do this is to set the item's control to a Composite
and then center the Label on the Composite. This is demonstrated in the
snippet below which is a modified Snippet58:
public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
ToolBar bar = new ToolBar (shell, SWT.BORDER);
for (int i=0; i<4; i++) {
ToolItem item = new ToolItem (bar, 0);
item.setText ("Item " + i);
}
ToolItem sep = new ToolItem (bar, SWT.SEPARATOR);
int start = bar.getItemCount ();
for (int i=start; i<start+4; i++) {
ToolItem item = new ToolItem (bar, 0);
item.setText ("Item " + i);
}
Composite composite = new Composite(bar, SWT.NONE);
composite.setLayout(new GridLayout());
Label label = new Label (composite, SWT.NONE);
label.setText("hi there");
label.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER,
false, false));
composite.pack ();
sep.setWidth (composite.getSize ().x);
sep.setControl (composite);
bar.pack ();
shell.pack ();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
HTH,
Grant
"Dave Smith" <dave.smith@xxxxxxxxxxx> wrote in message
news:fgsgu4$c8m$1@xxxxxxxxxxxxxxxxxxxx
> I am adding some Labels to a Toolbar widget.
> Is there some way that I can vertically center the label within the
toolbar?