[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Image adding in the coolbar

The label is stretching when the cool bar is resized but the image inside is
not.  If you want the image to stretch, you'll have to draw it yourself in a
cavas.

"S Dix" <siddhi1972@xxxxxxxxx> wrote in message
news:csru7o$h5j$1@xxxxxxxxxxxxxxxxxx
> I am trying to set an image in the coolbar. Somehow there is some space
> being left on both the right and left edges of the coolbar where I am
> adding the image. I am not sure why that is happening. I need to add my
> image completely in the coolbar. Below is the complete code
>
> import org.eclipse.swt.*;
> import org.eclipse.swt.graphics.*;
> import org.eclipse.swt.layout.FillLayout;
> import org.eclipse.swt.widgets.*;
>
> public class MySnippet {
>
> public static void main (String [] args) {
> Display display = new Display ();
> Shell shell = new Shell (display);
> FillLayout fillLayout = new FillLayout();
>   fillLayout.type = SWT.HORIZONTAL;
>   shell.setLayout(fillLayout);
>
> CoolBar bar = new CoolBar (shell, SWT.BORDER);
>
> Image image = new Image (display, 16, 16);
> Color color = display.getSystemColor (SWT.COLOR_RED);
> GC gc = new GC (image);
> gc.setBackground (color);
> gc.fillRectangle (image.getBounds ());
> gc.dispose ();
> CoolItem item = new CoolItem (bar, SWT.NONE);
> Label label = new Label (bar, SWT.BORDER);
> label.setImage (image);
> Point size = label.computeSize (SWT.DEFAULT, SWT.DEFAULT);
> item.setPreferredSize (item.computeSize (size.x, size.y));
> item.setControl(label);
> bar.pack ();
> shell.open ();
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> image.dispose ();
> display.dispose ();
> }
> }
>
> Any help appreciated
>