How to make a rectangle in Graphics in a transparent colour?

int alpha = 127; // 50% transparent
Color myColour = new Color(255, value, value, alpha);

See the Color constructors that take 4 arguments (of either int or float) for further details.


Try this: (but it will works for Graphics2D objeccts not for Graphics)

protected void paintComponent(Graphics2D g) {
    if (point != null) {
        int value = this.chooseColour(); // used to return how bright the red is needed
        g.setComposite(AlphaComposite.SrcOver.derive(0.8f));

        if(value !=0){
            Color myColour = new Color(255, value,value );
            g.setColor(myColour);
            g.fillRect(point.x, point.y, this.width, this.height);
        }
        else{
            Color myColour = new Color(value, 0,0 );
            g.setColor(myColour);
            g.fillRect(point.x, point.y, this.width, this.height);
        }

        g.setComposite(AlphaComposite.SrcOver); 
    }
}