Here you can find the source of setFont(HTMLDocument doc, Font font, Color fg)
Parameter | Description |
---|---|
doc | The document to modify. |
font | The font to use. |
fg | The default foreground color. |
public static void setFont(HTMLDocument doc, Font font, Color fg)
//package com.java2s; /*/*from w w w . j av a 2 s . com*/ * 08/13/2009 * * TipUtil.java - Utility methods for homemade tool tips. * * This library is distributed under a modified BSD license. See the included * RSyntaxTextArea.License.txt file for details. */ import java.awt.Color; import java.awt.Font; import javax.swing.text.html.HTMLDocument; public class Main { /** * Sets the default font for an HTML document (e.g., in a tool tip * displaying HTML). This is here because when rendering HTML, * {@code setFont()} is not honored. * * @param doc The document to modify. * @param font The font to use. * @param fg The default foreground color. */ public static void setFont(HTMLDocument doc, Font font, Color fg) { doc.getStyleSheet().addRule("body { font-family: " + font.getFamily() + "; font-size: " + font.getSize() + "pt" + "; color: " + getHexString(fg) + "; }"); } /** * Returns a hex string for the specified color, suitable for HTML. * * @param c The color. * @return The string representation, in the form "<code>#rrggbb</code>", * or <code>null</code> if <code>c</code> is <code>null</code>. */ private static String getHexString(Color c) { if (c == null) { return null; } StringBuilder sb = new StringBuilder("#"); int r = c.getRed(); if (r < 16) { sb.append('0'); } sb.append(Integer.toHexString(r)); int g = c.getGreen(); if (g < 16) { sb.append('0'); } sb.append(Integer.toHexString(g)); int b = c.getBlue(); if (b < 16) { sb.append('0'); } sb.append(Integer.toHexString(b)); return sb.toString(); } }