Transparent rectangle using awt ?

Hi,
This may sound like a bit of a silly question, but i was wondering if anyone knows how to draw a rectangle over the top of an image. So that i can see both the rectangle on top but also see the image underneath through it. Is this possible ?

It sounds like you are describing translucency.

AWT doesnt support translucency yet, just 1 bit transparency.

Hi .
As Jeff said, AWT doesn’t support translucency (it supports it, but it’s not hardware accelerated)
But you want to draw a rectangle over the image, this can be done with:


//in your rendering code
g.drawImage(image,x,y,....);
g.setColor(new Color(0,0,255,100)); //The last param is the alpha that goes from 0: transparent to 255: opaque
g.fillRect(rx,ry,rw,rh);

The only problem is that not being hardware acceleratred, this drops your performance and (almost) cannot be used in realtime applications.

I use this trick to indicate selections in my tile editor (the tile selected is highlighted in blue).

 Rafael.-

Yea, translucency was what i meant, not transparency ::slight_smile:

Thats brilliant rdcarvallo ! That’s exactly what i need i think and for exactly the same reason you use it ;D Will try it when i get in.