The transparent window or shaped window was supposedly not easy to do. I found that by tweaking in the awt of Java it worked kind of as I would like it to do. On Windows XP. NOT on MacOSX. 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 different Java implementations I guess. AND it’s hackish. No exception handling and there is alot of stuff that can go wrong I guess.

UPDATE! December 10 209, the java implementation was updated on MacOSX 10.6, to the current version available on windows. Nice and all, but the problem persists. Hmm. AWT? Workaround on the mac?

Read more on the subject right here:…

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()


// addNotify, here i am not sure if you have
// to add notify again.
//  frame.addNotify();
// frame.removeNotify();

void setup() {
size(200, 200);
frame.setAlwaysOnTop(true); // Alltid på topp
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];
int[] myYs = new int[4];
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);


wow, really cool thing! could you also achieve to set different opacities for the background? i’m trying, but somewhow i don’t get it.

Lämna ett svar