Johan_Wastring
YaBB Newbies
Offline
Posts: 28
Sweden
Re: how to hide window frame or set background opacity
Reply #3 - Sep 24th , 2009, 10:50pm
Hi I was kind of interested in this as well. I found that the transparent window worked fine. Also the shaped window which is demonstrated here. If labbed with some more you should find that you could do pretty much all you want to do, by tweaking the shaped window or tweaking the setOpaque or setOpacity which is two different things. Depending on what you want to do and depending on platform. Note! This code does not work on MacOSX. Due to Java different implementations I guess. AND it's hackish. No exception handling and there is alot of stuff that can go wrong I guess. Read more on the subject right here: http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/#Enabling-Per-Pixel-Translucency http://java.sun.com/docs/books/tutorial/uiswing/misc/trans_shaped_windows.html Heres the code I got working on Windows XP: import com.sun.awt.AWTUtilities; import java.awt.GraphicsDevice.*; // PC only import java.awt.Shape; import java.awt.geom.*; import javax.swing.*; public void init(){ // to make a frame not displayable, you can // use frame.removeNotify() frame.removeNotify(); frame.setUndecorated(true); // addNotify, here i am not sure if you have // to add notify again. // frame.addNotify(); // frame.removeNotify(); super.init(); } void setup() { size(200, 200); noStroke(); frame.setAlwaysOnTop(true); // Alltid på topp frame.setLocation(0,0); AWTUtilities.setWindowOpaque(frame, false); AWTUtilities.setWindowOpacity(frame, 0.9f); Shape shape = null; //shape = new Ellipse2D.Float(0, 0, frame.getWidth(), frame.getHeight()); //shape = new Ellipse2D.Float(0, 0, 200, 200); // shape = new RoundRectangle2D.Float(0, 0, 200, 200, 20, 20); //shape = new Polygon(int[] xpoints, int[] ypoints, int npoints) ; int[] myXes = new int[4]; myXes[0]=0; myXes[1]=150; myXes[2]=150; myXes[3]=0; int[] myYs = new int[4]; myYs[0]=0; myYs[1]=20; myYs[2]=180; myYs[3]=0; shape = new Polygon(myXes, myYs, 4) ; AWTUtilities.setWindowShape(frame, shape); } void draw() { setBackground(new Color(0,0,0,255)); // should work with normal background(255) command // frame.setVisible(true); fill(255, 0, 0, 255); // the alpha is not in play at this point - but it come into play when doing per-pixel translucency rect(23, 23, 54, 54); } /JohanWastring http://visualinformation.org