Is there a way to get the html color code from a JColorChooser
My java Applet takes three colors from the user and averages them and displays the color
I want to get the html color code after they look at the average color
how can I do that
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Write a method to convert a
Colorto aString.An HTML color code is just the R, G, and B values converted to hex and displayed as a string with a pound sign in front. This is a fairly simple method to write.
public static String toHexString(Color c) { StringBuilder sb = new StringBuilder("#"); if (c.getRed() < 16) sb.append('0'); sb.append(Integer.toHexString(c.getRed())); if (c.getGreen() < 16) sb.append('0'); sb.append(Integer.toHexString(c.getGreen())); if (c.getBlue() < 16) sb.append('0'); sb.append(Integer.toHexString(c.getBlue())); return sb.toString(); }