Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Image adding in the coolbar
Image adding in the coolbar [message #449334] Fri, 21 January 2005 22:03 Go to next message
S Dix is currently offline S DixFriend
Messages: 43
Registered: July 2009
Member
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
Re: Image adding in the coolbar [message #449449 is a reply to message #449334] Mon, 24 January 2005 18:02 Go to previous message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
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@yahoo.com> wrote in message
news:csru7o$h5j$1@www.eclipse.org...
> 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
>
Previous Topic:Border around disabled Text in Eclipse Form
Next Topic:Colors on linux/gtk
Goto Forum:
  


Current Time: Thu Nov 14 05:59:14 GMT 2019

Powered by FUDForum. Page generated in 0.01484 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top