--- old/modules/javafx.web/src/main/java/javafx/scene/web/HTMLEditorSkin.java 2017-12-26 19:30:47.919413082 +0530 +++ new/modules/javafx.web/src/main/java/javafx/scene/web/HTMLEditorSkin.java 2017-12-26 19:30:47.643275082 +0530 @@ -1029,14 +1029,14 @@ fgColorButton.setDisable(!isCommandEnabled(FOREGROUND_COLOR.getCommand())); String foregroundColorValue = getCommandValue(FOREGROUND_COLOR.getCommand()); if (foregroundColorValue != null) { - Color c = Color.web(rgbToHex((String)foregroundColorValue)); + Color c = getColor(foregroundColorValue); fgColorButton.setValue(c); } bgColorButton.setDisable(!isCommandEnabled(BACKGROUND_COLOR.getCommand())); String backgroundColorValue = getCommandValue(BACKGROUND_COLOR.getCommand()); if (backgroundColorValue != null) { - Color c = Color.web(rgbToHex((String)backgroundColorValue)); + Color c = getColor(backgroundColorValue); bgColorButton.setValue(c); } @@ -1119,29 +1119,16 @@ return webPage.queryCommandValue(command); } - private static String rgbToHex(String value) { - if (value.startsWith("rgba")) { - String[] components = value.substring(value.indexOf('(') + 1, value.lastIndexOf(')')).split(","); - value = String.format("#%02X%02X%02X%02X", - Integer.parseInt(components[0].trim()), - Integer.parseInt(components[1].trim()), - Integer.parseInt(components[2].trim()), - Integer.parseInt(components[3].trim())); - // The default background color for WebView, according to the HTML - // standard is rgba=#00000000 (black). The canvas background is expected - // to be white. - if ("#00000000".equals(value)) { - return "#FFFFFFFF"; - } - } else if (value.startsWith("rgb")) { - String[] components = value.substring(value.indexOf('(') + 1, value.lastIndexOf(')')).split(","); - value = String.format("#%02X%02X%02X", - Integer.parseInt(components[0].trim()), - Integer.parseInt(components[1].trim()), - Integer.parseInt(components[2].trim())); + private Color getColor(String value) { + Color color = Color.web(value); + /* The default background color for WebView, according to the HTML + * standard is rgba=#00000000 (black). The canvas background is expected + * to be white. + */ + if (color.toString().equals("0x00000000")) { + color = Color.web("#FFFFFFFF"); } - - return value; + return color; } private void applyTextFormatting() {