Skip to main content

[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

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

begin:vcard
fn:nicksoftware company limited
n:company limited;nicksoftware
org:;Software Development
adr:T. Suthep A. Mueang;;142/9 T. Suandok Soi 6;Chiangmai;;50200;Thailand
email;internet:nick@xxxxxxxxxxxxxxxx
tel;work:+66 53 281 844
tel;cell:+66 810 25 80 11
x-mozilla-html:FALSE
url:http://www.nicksoftware.co.th
version:2.1
end:vcard


Back to the top