javax.swing.text.html.StyleSheet类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(183)

本文整理了Java中javax.swing.text.html.StyleSheet类的一些代码示例,展示了StyleSheet类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StyleSheet类的具体详情如下:
包路径:javax.swing.text.html.StyleSheet
类名称:StyleSheet

StyleSheet介绍

暂无

代码示例

代码示例来源:origin: org.netbeans.api/org-openide-dialogs

public FixedHeightPane () {
  super ();
  setEditable(false);
  HTMLEditorKit htmlkit = new HTMLEditorKit();
  StyleSheet css = htmlkit.getStyleSheet();
  if (css.getStyleSheets() == null) {
    StyleSheet css2 = new StyleSheet();
    Font f = new JList().getFont();
    int size = f.getSize();
    try {
      css2.addRule(new StringBuffer("body { font-size: ").append(size) // NOI18N
          .append("; font-family: ").append(f.getName()).append("; }").toString()); // NOI18N
      css2.addStyleSheet(css);
      htmlkit.setStyleSheet(css2);
    } catch( RuntimeException ex ) {

代码示例来源:origin: bobbylight/RSyntaxTextArea

/**
 * 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: " + HtmlUtil.getHexString(fg) + "; }");
}

代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop

/**
 * Sets the font used for HTML displays to the specified font. Components
 * that display HTML do not necessarily honor font properties, since the
 * HTML document can override these values. Calling {@code setHtmlFont}
 * after the data is set will force the HTML display to use the font
 * specified to this method.
 * 
 * @param doc
 *            the HTML document to update
 * @param font
 *            the font to use
 * @throws NullPointerException
 *             if any parameter is {@code null}
 */
public static void setHtmlFont(HTMLDocument doc, Font font) {
  String stylesheet = String.format(STYLESHEET, font.getName(),
      font.getSize(), font.getName(), font.getSize());
  
  try {
    doc.getStyleSheet().loadRules(new StringReader(stylesheet), null);
  } catch (IOException e) {
    //this should never happen with our sheet
    throw new IllegalStateException(e);
  }
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

font = new Font("SansSerif", Font.PLAIN, 12);
doc.getStyleSheet().addRule(
    "a { color: " + HtmlUtil.getHexString(linkFG) + "; }");

代码示例来源:origin: omegat-org/omegat

@Override
public void setFont(Font font) {
  super.setFont(font);
  Document doc = getDocument();
  if (!(doc instanceof HTMLDocument)) {
    return;
  }
  StyleSheet styleSheet = ((HTMLDocument) doc).getStyleSheet();
  styleSheet.addRule("body { font-family: " + font.getName() + "; "
      + " font-size: " + font.getSize() + "; "
      + " font-style: " + (font.getStyle() == Font.BOLD ? "bold"
          : font.getStyle() == Font.ITALIC ? "italic" : "normal") + "; "
      + " color: " + EditorColor.COLOR_FOREGROUND.toHex() + "; "
      + " background: " + EditorColor.COLOR_BACKGROUND.toHex() + "; "
      + " }");
}

代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin

@NotNull
 public static JTextPane createDescriptionPane() {
  JTextPane result = new JTextPane();
  result.addHyperlinkListener(new BrowserHyperlinkListener());
  result.setContentType("text/html");
  Font descriptionFont = UIUtil.getLabelFont(UIUtil.FontSize.SMALL);
  HTMLEditorKit editorKit = UIUtil.getHTMLEditorKit();
  editorKit.getStyleSheet().addRule("body, p {" +
                   "color:#" + ColorUtil.toHex(UIUtil.getLabelFontColor(UIUtil.FontColor.BRIGHTER)) + ";" +
                   "font-family:" + descriptionFont.getFamily() + ";" +
                   "font-size:" + descriptionFont.getSize() + "pt;}");
  result.setHighlighter(null);
  result.setEditorKit(editorKit);
  return result;
 }
}

代码示例来源:origin: JetBrains/jediterm

public static HTMLEditorKit getHTMLEditorKit(boolean noGapsBetweenParagraphs) {
  Font font = getLabelFont();
  @NonNls String family = !SystemInfo.isWindows && font != null ? font.getFamily() : "Tahoma";
  int size = font != null ? font.getSize() : JBUI.scale(11);
  String customCss = String.format("body, div, p { font-family: %s; font-size: %s; }", family, size);
  if (noGapsBetweenParagraphs) {
    customCss += " p { margin-top: 0; }";
  }
  final StyleSheet style = new StyleSheet();
  style.addStyleSheet(isUnderDarcula() ? (StyleSheet) UIManager.getDefaults().get("StyledEditorKit.JBDefaultStyle") : DEFAULT_HTML_KIT_CSS);
  style.addRule(customCss);
  return new HTMLEditorKit() {
    @Override
    public StyleSheet getStyleSheet() {
      return style;
    }
  };
}

代码示例来源:origin: protegeproject/protege

if (font != null) {
  String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: 12pt; }";
  ((HTMLDocument) pane.getDocument()).getStyleSheet().addRule(bodyRule);

代码示例来源:origin: MegaMek/megamek

public static void setupStylesheet(JTextPane pane) {
    pane.setContentType("text/html");
    Font font = UIManager.getFont("Label.font");
    ((HTMLEditorKit) pane.getEditorKit()).getStyleSheet().addRule(
        "pre { font-family: " + font.getFamily()
            + "; font-size: 12pt; font-style:normal;}");
  }    
}

代码示例来源:origin: cytoscape.coreplugins/biopax

public static void modifyStyleSheetForSingleDocument(JTextPane textPane) {
  HTMLDocument htmlDoc = (HTMLDocument) textPane.getDocument();
  StyleSheet styleSheet = htmlDoc.getStyleSheet();
  styleSheet.addRule("h2 {color: #663333; font-size: 120%; font-weight: bold; "
      + "margin-bottom:3px}");
  styleSheet.addRule("h3 {color: #663333; font-size: 105%; font-weight: bold;"
      + "margin-bottom:7px}");
  styleSheet.addRule("ul { list-style-type: none; margin-left: 5px; "
      + "padding-left: 1em;	text-indent: -1em;}");
  styleSheet.addRule("h4 {color: #66333; font-weight: bold; margin-bottom:3px;}");
  styleSheet.addRule(".link {color:blue; text-decoration: underline;}");
  styleSheet.addRule(".description {font-size: 85%;}");
  styleSheet.addRule(".rule {font-size: 90%; font-weight:bold}");
  styleSheet.addRule(".excerpt {font-size: 90%;}");
}

代码示例来源:origin: stackoverflow.com

JEditorPane jEditorPane = new JEditorPane();
HTMLEditorKit kit = new HTMLEditorKit();
StyleSheet styleSheet = kit.getStyleSheet();
styleSheet.addRule("A {color:red}"); //change links to red
jEditorPane.setEditorKit(kit);

代码示例来源:origin: runelite/runelite

public JRichTextPane()
{
  super();
  setHighlighter(null);
  setEditable(false);
  setOpaque(false);
  enableAutoLinkHandler(true);
  setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
  HTMLEditorKit ek = (HTMLEditorKit) getEditorKitForContentType("text/html");
  ek.getStyleSheet().addRule("a {color: #DDDDDD }");
}

代码示例来源:origin: stackoverflow.com

HTMLEditorKit kit = new HTMLEditorKit();
StyleSheet styleSheet = kit.getStyleSheet();
styleSheet.addRule("a:hover{color:red;}");
Document doc = kit.createDefaultDocument();
String htmlString = "<a href='stackoverflow.com'>Go to StackOverflow!</a>";
// your JEditorPane
jEditorPane.setDocument(doc);
jEditorPane.setText(htmlString);

代码示例来源:origin: freeplane/freeplane

/**
 * Overriden to return our own slimmed down style sheet.
 */
public StyleSheet getStyleSheet() {
  if (defaultStyles == null) {
    defaultStyles = new StyleSheet();
    StringReader r = new StringReader(ScaledHTML.styleChanges);
    try {
      defaultStyles.loadRules(r, null);
    }
    catch (Throwable e) {
      // don't want to die in static initialization... 
      // just display things wrong.
    }
    r.close();
    defaultStyles.addStyleSheet(super.getStyleSheet());
  }
  return defaultStyles;
}

代码示例来源:origin: com.google.code.findbugs/findbugs

private void setStyleSheets() {
  StyleSheet styleSheet = new StyleSheet();
  styleSheet.addRule("body {font-size: " + Driver.getFontSize() + "pt}");
  styleSheet.addRule("H1 {color: red;  font-size: 120%; font-weight: bold;}");
  styleSheet.addRule("code {font-family: courier; font-size: " + Driver.getFontSize() + "pt}");
  styleSheet.addRule(" a:link { color: #0000FF; } ");
  styleSheet.addRule(" a:visited { color: #800080; } ");
  styleSheet.addRule(" a:active { color: #FF0000; text-decoration: underline; } ");
  HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
  htmlEditorKit.setStyleSheet(styleSheet);
  mainFrame.summaryHtmlArea.setEditorKit(htmlEditorKit);
}

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-bu

final HTMLDocument hd=(HTMLDocument)kit_.createDefaultDocument();
  kit_.read(new StringReader(_source),hd,0);
  hd.setBase(_url);
  hd.putProperty("IgnoreCharsetDirective",Boolean.TRUE);
  kit_.read
   (new InputStreamReader
    (getInputStreamFor(_url),"iso-8859-1"),hd,0);
updateStyles(hd.getStyleSheet());
 StyleSheet ss=hd.getStyleSheet();
 StyleSheet[] as=ss.getStyleSheets();
 if(as!=null)
  for(int i=0;i<as.length;i++)
   ss.removeStyleSheet(as[i]);
 Enumeration rules=ss.getStyleNames();
 while (rules.hasMoreElements())
  ss.removeStyle(name);

代码示例来源:origin: stackoverflow.com

String htmlString = "<body><h1>Karaoke Beyonce song</h1><p><span class="highlight">Hello</span>world</p></body>";

JEditorPane   pane = new JEditorPane();
HTMLEditorKit kit  = new HTMLEditorKit();

pane.setEditable(false);
pane.setEditorKit(kit);

StyleSheet sh = editorKit.getStyleSheet();
sh.addRule("span.highlight {background-color:yellow}");

Document doc = kit.createDefaultDocument();
pane.setDocument(doc);
pane.setText(htmlString);

代码示例来源:origin: freeplane/freeplane

public Document createDefaultDocument(JLabel c) {
    Font font = c.getFont();
    Color foreground = c.getForeground();
    StyleSheet styles = getStyleSheet();
    StyleSheet ss = new ScaledStyleSheet();
    ss.addStyleSheet(styles);
    HTMLDocument doc = new HTMLDocument(ss);
    doc.setPreservesUnknownTags(false);
    doc.getStyleSheet().addRule(new StringBuffer("body {").append(new CssRuleBuilder()
    .withCSSFont(font, UITools.FONT_SCALE_FACTOR)
    .withColor(foreground)
    .withAlignment(c.getHorizontalAlignment())).append("}").toString());
    doc.setParser(getParser());
    doc.setAsynchronousLoadPriority(Integer.MAX_VALUE);
    doc.setPreservesUnknownTags(false);
    return doc;
  }
}

代码示例来源:origin: stackoverflow.com

public static void setDefaultStyle()
{
  // looks like WTF but that is the way to set default CSS
  StyleSheet sheet=new HTMLEditorKit().getStyleSheet();
  // add your rules
  sheet.addRule("...");
  sheet.addRule("...");
}

代码示例来源:origin: freeplane/freeplane

private void setTipTextUnsafe(String tipText) throws Exception{
  tip.setSize(0, 0);
  tip.setPreferredSize(null);
  tip.setText(tipText);
  ((HTMLDocument)tip.getDocument()).setBase(baseUrl);
  Dimension preferredSize = tip.getPreferredSize();
  if (preferredSize.width > maximumWidth && contentType.equals(FreeplaneTooltip.TEXT_HTML)) {
    final HTMLDocument document = (HTMLDocument) tip.getDocument();
    document.getStyleSheet().addRule("body { width: " + maximumWidth  + "}");
    // bad hack: call "setEditable" only to update view
    tip.setEditable(true);
    tip.setEditable(false);
    preferredSize = tip.getPreferredSize();
    if (preferredSize.width > maximumWidth) {
    }
  }
  tip.setSize(preferredSize);
  preferredSize = tip.getPreferredSize();
  tip.setPreferredSize(preferredSize);
}

相关文章