Jump to content

Req paint help with transparency


Recommended Posts

Posted

If anybody knows the command/method used to alter the transparency of a fillRect() for paint that would be great. I tried looking it up and saw that it might be called alpha to alter this, however I can't figure out how to change alpha. The only command i can see is getAlpha(). If anyone could provide me with an example that would be great. I'm sure I can figure it out from there!

Thanks in advance!

Posted

 

Use a transparent color.

Color has multiple constructors. The one that takes 4 int arguments is the one you want. The last argument is the "alpha":

Color color = new Color(255, 0, 0, 100);

void onPaint(Graphics2D g) {
    g.setColor(color);
    g.fillRect(...);
}

 

This^

 

It is worth noting that, like the RGB values, the alpha constructor is also in the range 0-255 where 255 is solid colour.

 

apa

  • Like 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...