javax.swing.text.html.StyleSheet.addRule()方法的使用及代码示例

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

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

StyleSheet.addRule介绍

暂无

代码示例

代码示例来源: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: 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: 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.netbeans.api/org-openide-dialogs

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);

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

doc.getStyleSheet().addRule(
    "a { color: " + HtmlUtil.getHexString(linkFG) + "; }");

代码示例来源: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: 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: SonarSource/sonarlint-intellij

public SonarLintRulePanel(Project project, ProjectBindingManager projectBindingManager) {
 this.project = project;
 this.projectBindingManager = projectBindingManager;
 this.kit = new CustomHTMLEditorKit();
 StyleSheet styleSheet = kit.getStyleSheet();
 styleSheet.addRule("td {align:center;}");
 styleSheet.addRule("td.pad {padding: 0px 10px 0px 0px;}");
 panel = new JPanel(new BorderLayout());
 panel.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT));
 setRuleKey(null);
 show();
}

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

/**
   * Sets the default font and default color. These are set by
   * adding a rule for the body that specifies the font and color.
   * This allows the html to override these should it wish to have
   * a custom font or color.
   */
  private void setFontAndColor(Font font, Color fg) {
      getStyleSheet().addRule(displayPropertiesToCSS(font,fg));
  }
}

代码示例来源:origin: org.bidib.jbidib.swinglabs.swingx/swingx-core

/**
   * Sets the default font and default color. These are set by
   * adding a rule for the body that specifies the font and color.
   * This allows the html to override these should it wish to have
   * a custom font or color.
   */
  private void setFontAndColor(Font font, Color fg) {
      getStyleSheet().addRule(displayPropertiesToCSS(font,fg));
  }
}

代码示例来源:origin: com.haulmont.thirdparty/swingx-core

/**
   * Sets the default font and default color. These are set by
   * adding a rule for the body that specifies the font and color.
   * This allows the html to override these should it wish to have
   * a custom font or color.
   */
  private void setFontAndColor(Font font, Color fg) {
      getStyleSheet().addRule(displayPropertiesToCSS(font,fg));
  }
}

代码示例来源:origin: org.swinglabs.swingx/swingx-core

/**
   * Sets the default font and default color. These are set by
   * adding a rule for the body that specifies the font and color.
   * This allows the html to override these should it wish to have
   * a custom font or color.
   */
  private void setFontAndColor(Font font, Color fg) {
      getStyleSheet().addRule(displayPropertiesToCSS(font,fg));
  }
}

代码示例来源: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: senbox-org/snap-desktop

private static void setFont(JEditorPane textPane) {
  if (textPane.getDocument() instanceof HTMLDocument) {
    Font font = UIManager.getFont("Label.font");
    String bodyRule = "body { font-family: " + font.getFamily() + "; font-size: " + font.getSize() + "pt; }";
    ((HTMLDocument) textPane.getDocument()).getStyleSheet().addRule(bodyRule);
  }
}

代码示例来源: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: org.fudaa.framework.ctulu/ctulu-bu

public static View drawHtmlText(Graphics _g, JComponent _parent, String _text, Rectangle _bounds) {
 if (_text == null || _text.equals("")) {
  return null;
 }
 View v = BasicHTML.createHTMLView(_parent, _text);
 HTMLDocument doc=(HTMLDocument)v.getDocument();
 doc.getStyleSheet().addRule("body { color: #000000,padding:2px}");
 v.paint(_g, _bounds);
 return v;
}

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

private void setLineWrap() {
  if(null != textfield.getClientProperty("EditNodeTextField.linewrap") || inputMethodInUseListener.isIMEInUse()){
    return;
  }
  final HTMLDocument document = (HTMLDocument) textfield.getDocument();
  document.getStyleSheet().addRule("body { width: " + (maxWidth - 1) + "}");
  // bad hack: call "setEditable" only to update view
  textfield.setEditable(false);
  textfield.setEditable(true);
  textfield.putClientProperty("EditNodeTextField.linewrap", true);
}

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

private void updateStyle(@NotNull JEditorPane pane) {
  EditorKit kit = pane.getEditorKit();
  if (kit instanceof HTMLEditorKit) {
   StyleSheet css = ((HTMLEditorKit)kit).getStyleSheet();
   css.addRule("body, p {" +
         "color:#" + ColorUtil.toHex(getForeground()) + ";" +
         "font-family:" + getFont().getFamily() + ";" +
         "font-size:" + getFont().getSize() + "pt;" +
         "white-space:nowrap;}");
  }
 }
}

代码示例来源:origin: aterai/java-swing-tips

private MainPanel() {
 super(new GridLayout(3, 1));
 add(makeUrlPanel("Default", HREF));
 // Customize detault html link color in java swing - Stack Overflow
 // https://stackoverflow.com/questions/26749495/customize-detault-html-link-color-in-java-swing
 HTMLEditorKit kit = new HTMLEditorKit();
 StyleSheet styleSheet = kit.getStyleSheet();
 styleSheet.addRule("a{color:#FF0000;}");
 add(makeUrlPanel("styleSheet.addRule(\"a{color:#FF0000;}\")", HREF));
 add(makeUrlPanel("<a style='color:#00FF00'...", String.format("<html><a style='color:#00FF00' href='%s'>%s</a>", MYSITE, MYSITE)));
 setPreferredSize(new Dimension(320, 240));
}

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

private void initView() {
 String text = getText();
 if (getGrid() == null) return;
 if (CtuluLibString.isEmpty(text)) {
  text = "<html><body><p></p></body></html>";
  setW(10);
  setH(10);
 }
 view_ = BasicHTML.createHTMLView(getGrid(), text);
 HTMLDocument doc = (HTMLDocument) view_.getDocument();
 doc.getStyleSheet().addRule("body { color: #000000;padding: 4px}");
}

相关文章