[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [platform-swt-dev] Cannot layout new widgets on a non rectangular shell
|
Hi, Abhishek,
I think it would be easier in this case to just draw your label text on
the shell instead of using a control.
For example, delete the Composite and CLabel code, and add something like
the following to the Paint event, right after the drawImage:
e.gc.drawString("Hello there", imageData.x + 10, imageData.y, true
);
Also, please note that CLabel does not support SWT.WRAP style.
Nick,
Please use SWT.NONE instead of SWT.NO when creating a Composite or Button
with none of their style bits set.
Hope this helps,
Carolyn
nick <nick@xxxxxxxxxxxxxxxx>
Sent by: platform-swt-dev-bounces@xxxxxxxxxxx
04/02/2007 08:40 PM
Please respond to
"Eclipse Platform SWT component developers list."
<platform-swt-dev@xxxxxxxxxxx>
To
"Eclipse Platform SWT component developers list."
<platform-swt-dev@xxxxxxxxxxx>
cc
Subject
Re: [platform-swt-dev] Cannot layout new widgets on a non rectangular
shell
I don't think that this is related to the non-rectangular shape of the
shell. Looks
more like a layout problem.
replace
-----------------------
final Composite comp = new Composite(shell, SWT.NONE);
comp.setBackgroundMode(SWT.INHERIT_FORCE);
GridLayout layout = new GridLayout(1, false);
.
.
-----------------------
with
-----------------------
Composite composite = new Composite(shell, SWT.NO);
composite.setLayout(new FillLayout());
Button button1 = new Button(shell, SWT.NO);
button1.setLocation(5, 5);
button1.setSize(150, 20);
button1.setText("hello");
-----------------------
and the button will show up
/nick
Abhishek Misra wrote:
> Created from snippet 219.
>
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet219.java?view=co
> <
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet219.java?view=co
>
>
> I changed the image in the above snippet to a bigger 500*200 image
> which is transparent and use that.
>
> I am trying to create a new composite on the shell created in above
> step and put a label on it, but it doesn't work. All that shows up is
> shell with the image.
>
> final Display display = new Display ();
> final Image image = ImageManager.getImage("info_window.png");
> final Shell shell = new Shell (display, SWT.NO_TRIM);
> Region region = new Region();
> final ImageData imageData = image.getImageData();
> if (imageData.alphaData != null) {
> Rectangle pixel = new Rectangle(0, 0, 1, 1);
> for (int y = 0; y < imageData.height; y++) {
> for (int x = 0; x < imageData.width; x++) {
> if (imageData.getAlpha(x, y) == 255) {
> pixel.x = imageData.x + x;
> pixel.y = imageData.y + y;
> region.add(pixel);
> }
> }
> }
> } else {
> ImageData mask = imageData.getTransparencyMask();
> Rectangle pixel = new Rectangle(0, 0, 1, 1);
> for (int y = 0; y < mask.height; y++) {
> for (int x = 0; x < mask.width; x++) {
> if (mask.getPixel(x, y) != 0) {
> pixel.x = imageData.x + x;
> pixel.y = imageData.y + y;
> region.add(pixel);
> }
> }
> }
> }
> shell.setRegion(region);
>
> final Composite comp = new Composite(shell, SWT.NONE);
> comp.setBackgroundMode(SWT.INHERIT_FORCE);
> GridLayout layout = new GridLayout(1, false);
> layout.marginRight = 10;
> comp.setLayout(layout);
> GridData data = new GridData(GridData.FILL_BOTH);
> comp.setLayoutData(data);
> CLabel label = new CLabel(comp, SWT.WRAP);
> label.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
>
> final GridData textData = new
> GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
> textData.horizontalIndent = 0;
> textData.verticalIndent = 0;
> label.setLayoutData(textData);
> label.setBackgroundMode(SWT.INHERIT_DEFAULT);
>
> Listener l = new Listener() {
> int startX, startY;
> public void handleEvent(Event e) {
> if (e.type == SWT.KeyDown && e.character == SWT.ESC) {
> shell.dispose();
> }
> if (e.type == SWT.MouseDown && e.button == 1) {
> startX = e.x;
> startY = e.y;
> }
> if (e.type == SWT.MouseMove && (e.stateMask &
> SWT.BUTTON1) != 0) {
> Point p = shell.toDisplay(e.x, e.y);
> p.x -= startX;
> p.y -= startY;
> shell.setLocation(p);
> }
> if (e.type == SWT.Paint) {
> e.gc.drawImage(image, imageData.x, imageData.y);
> }
> }
> };
> shell.addListener(SWT.KeyDown, l);
> shell.addListener(SWT.MouseDown, l);
> shell.addListener(SWT.MouseMove, l);
> shell.addListener(SWT.Paint, l);
>
> shell.setSize(imageData.x + imageData.width, imageData.y +
> imageData.height);
> shell.layout();
> shell.open ();
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ())
> display.sleep ();
> }
> region.dispose();
> image.dispose ();
> display.dispose ();
> }
>
> Any idea what's wrong?
>
>
>
> Thanks,
> abhi
>
>------------------------------------------------------------------------
>
>_______________________________________________
>platform-swt-dev mailing list
>platform-swt-dev@xxxxxxxxxxx
>https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
>
>
_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
Attachment:
nick.vcf
Description: Binary data