Jump to content

Req paint help with transparency


Strange_Fk

Recommended Posts

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!

Link to comment
Share on other sites

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(...);
}
Edited by fixthissite
  • Like 3
Link to comment
Share on other sites

 

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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