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);
}
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.