public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Widget");

    final Table table = new Table(shell, SWT.MULTI);
    table.setLinesVisible(true);
    table.setBounds(10, 10, 100, 100);
    for (int i = 0; i < 9; i++) {
      new TableItem(table, SWT.NONE).setText("item" + i);
    }

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Capture");
    button.pack();
    button.setLocation(10, 140);
    button.addListener(
        SWT.Selection,
        event -> {
          Point tableSize = table.getSize();
          GC gc = new GC(table);
          final Image image = new Image(display, tableSize.x, tableSize.y);
          gc.copyArea(image, 0, 0);
          gc.dispose();

          Shell popup = new Shell(shell);
          popup.setText("Image");
          popup.addListener(SWT.Close, e -> image.dispose());

          Canvas canvas = new Canvas(popup, SWT.NONE);
          canvas.setBounds(10, 10, tableSize.x + 10, tableSize.y + 10);
          canvas.addPaintListener(e -> e.gc.drawImage(image, 0, 0));
          popup.pack();
          popup.open();
        });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
  public static void main(String[] args) {
    final Display display = new Display();
    // Shell must be created with style SWT.NO_TRIM
    final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP);
    shell.setBackground(display.getSystemColor(SWT.COLOR_RED));
    // define a region that looks like a key hole
    Region region = new Region();
    region.add(circle(67, 67, 67));
    region.subtract(circle(20, 67, 50));
    region.subtract(new int[] {67, 50, 55, 105, 79, 105});
    // define the shape of the shell using setRegion
    shell.setRegion(region);
    Rectangle size = region.getBounds();
    shell.setSize(size.width, size.height);
    // add ability to move shell around
    Listener l =
        new Listener() {
          /** The x/y of the MouseDown, relative to top-left of the shell. */
          Point origin;

          @Override
          public void handleEvent(Event e) {
            switch (e.type) {
              case SWT.MouseDown:
                Point point = shell.toDisplay(e.x, e.y);
                Point loc = shell.getLocation();
                origin = new Point(point.x - loc.x, point.y - loc.y);
                break;
              case SWT.MouseUp:
                origin = null;
                break;
              case SWT.MouseMove:
                if (origin != null) {
                  Point p = display.map(shell, null, e.x, e.y);
                  shell.setLocation(p.x - origin.x, p.y - origin.y);
                }
                break;
            }
          }
        };
    shell.addListener(SWT.MouseDown, l);
    shell.addListener(SWT.MouseUp, l);
    shell.addListener(SWT.MouseMove, l);
    // add ability to close shell
    Button b = new Button(shell, SWT.PUSH);
    b.setBackground(shell.getBackground());
    b.setText("close");
    b.pack();
    b.setLocation(10, 68);
    b.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event e) {
            shell.close();
          }
        });
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    region.dispose();
    display.dispose();
  }