/** * Update the color in the default style of the document. * * @param color the new color to use or null to remove the color attribute from the document's * style */ private void updateForeground(Color color) { StyledDocument doc = (StyledDocument) getComponent().getDocument(); Style style = doc.getStyle(StyleContext.DEFAULT_STYLE); if (style == null) { return; } if (color == null) { style.removeAttribute(StyleConstants.Foreground); } else { StyleConstants.setForeground(style, color); } }