Reputation: 189
I want to make a shape transparant (the shape should be semi-opaque). How can I do this in Java? This is a part of my code:
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.red);
g.fillOval(40, 40, 40, 40);
}
Upvotes: 1
Views: 2743
Reputation: 15156
The color you are currently using, Color.RED
, does not use alpha, which is basically how transparent your color will be.
g.setColor(new Color(255, 0, 0, 125));
This will create a new color, using RGBA. The color I created uses 255 for red, 0 for blue and 0 for green. 125 is the alpha
Upvotes: 2