In my Java application, I was able to get the Color
of a JButton
in terms of red, green and blue; I have stored these values in three int
s.
How do I convert those RGB values into a String
containing the equivalent hexadecimal representation? Such as #0033fA
Color your_color = new Color(128,128,128); String hex = "#"+Integer. toHexString(your_color. getRGB()). substring(2);
You can use
String hex = String.format("#%02x%02x%02x", r, g, b);
Use capital X's if you want your resulting hex-digits to be capitalized (#FFFFFF
vs. #ffffff
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With