You can write a simple RGB-to-String converter:
public final class Helper {
public static String RgbToHex(int r, int g, int b){
StringBuilder sb = new StringBuilder();
sb.append('#')
.append(Integer.toHexString(r))
.append(Integer.toHexString(g))
.append(Integer.toHexString(b));
return sb.toString();
}
}
And use it:
nameField.getElement().getStyle().setBackgroundColor(Helper.RgbToHex(50, 100, 150));
---Update---
More complex way with controlling of negative value, great than 255, and 0-15 value.
public static String RgbToHex(int r, int g, int b){
StringBuilder sb = new StringBuilder();
sb.append('#')
.append(intTo2BytesStr(r))
.append(intTo2BytesStr(g))
.append(intTo2BytesStr(b));
return sb.toString();
}
private static String intTo2BytesStr(int i) {
return pad(Integer.toHexString(intTo2Bytes(i)));
}
private static int intTo2Bytes(int i){
return (i < 0) ? 0 : (i > 255) ? 255 : i;
}
private static String pad(String str){
StringBuilder sb = new StringBuilder(str);
if (sb.length()<2){
sb.insert(0, '0');
}
return sb.toString();
}