示例#1
0
  /**
   * Update the font in the default style of the document.
   *
   * @param font the new font to use or null to remove the font attribute from the document's style
   */
  private void updateFont(Font font) {
    StyledDocument doc = (StyledDocument) getComponent().getDocument();
    Style style = doc.getStyle(StyleContext.DEFAULT_STYLE);

    if (style == null) {
      return;
    }

    if (font == null) {
      style.removeAttribute(StyleConstants.FontFamily);
      style.removeAttribute(StyleConstants.FontSize);
      style.removeAttribute(StyleConstants.Bold);
      style.removeAttribute(StyleConstants.Italic);
    } else {
      StyleConstants.setFontFamily(style, font.getName());
      StyleConstants.setFontSize(style, font.getSize());
      StyleConstants.setBold(style, font.isBold());
      StyleConstants.setItalic(style, font.isItalic());
    }
  }
示例#2
0
  /**
   * 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);
    }
  }