Results 1 to 1 of 1
-
Creating a non-rectangular shell to simulate transparency
Java Code:import org.eclipse.swt.SWT; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Region; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class Snippet180 { public static void main(String[] args) { Display display = new Display(); final Image image = display.getSystemImage(SWT.ICON_WARNING); // 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 Region region = new Region(); Rectangle pixel = new Rectangle(0, 0, 1, 1); for (int y = 0; y < 200; y += 2) { for (int x = 0; x < 200; x += 2) { pixel.x = x; pixel.y = y; region.add(pixel); } } // define the shape of the shell using setRegion shell.setRegion(region); Rectangle size = region.getBounds(); shell.setSize(size.width, size.height); shell.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bounds = image.getBounds(); Point size = shell.getSize(); e.gc.drawImage(image, 0, 0, bounds.width, bounds.height, 10, 10, size.x - 20, size.y - 20); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } region.dispose(); display.dispose(); } }"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Similar Threads
-
How to create a Dialog Shell
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 07:52 PM -
Conversion between polar and rectangular coordinates
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 10:55 PM -
simulate form type=button press with java application
By redmoonzer01 in forum NetworkingReplies: 1Last Post: 03-29-2008, 06:28 AM -
simulate message box
By pablitohh in forum New To JavaReplies: 1Last Post: 12-05-2007, 04:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks