示例#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
 /**
  * Sets the font of the specified attribute.
  *
  * @param attr attribute to apply this font to
  * @param f the font to use
  */
 public static void setAttributeFont(MutableAttributeSet attr, Font f) {
   StyleConstants.setBold(attr, f.isBold());
   StyleConstants.setItalic(attr, f.isItalic());
   StyleConstants.setFontFamily(attr, f.getFamily());
   StyleConstants.setFontSize(attr, f.getSize());
 }