简体   繁体   中英

Java set transparency on Color.color WITHOUT using rgb's

I'm woundering, is there a way to set transparency on a color without using rgb's. For example you can do this

Color color = new Color(255,255,255,Transparency) 

but I want to use it this way

Color = new Color(Color.red,Transparency)

It doesn't look like there's any such method or constructor at the moment, but it's dead easy to write a helper method:

public static Color newColorWithAlpha(Color original, int alpha) {
    return new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
}

You can import that statically, at which point you'd have:

Color color = newColorWithAlpha(Color.red, 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM