tags:

views:

45

answers:

2

in my swing application i was able to get the value of JButton color in terms of Red green blue values and i have stored these values in three integers, how to convert RGB values into hexadecimal value.

example i need in these format "#0033fA"

+1  A: 
int r, g, b;
Color color = new Color();
String hex = Integer.toHexString(color.getRGB() & 0xffffff);
if (hex.length < 6) {
    hex = "0" + hex;
}
hex = "#" + hex;
Vivien Barousse
+5  A: 

you can use String hex = String.format("#%02x%02x%02x", r, g, b);

mohammad shamsi