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

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

本文整理了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

  1. @NotNull
  2. public static JTextPane createDescriptionPane() {
  3. JTextPane result = new JTextPane();
  4. result.addHyperlinkListener(new BrowserHyperlinkListener());
  5. result.setContentType("text/html");
  6. Font descriptionFont = UIUtil.getLabelFont(UIUtil.FontSize.SMALL);
  7. HTMLEditorKit editorKit = UIUtil.getHTMLEditorKit();
  8. editorKit.getStyleSheet().addRule("body, p {" +
  9. "color:#" + ColorUtil.toHex(UIUtil.getLabelFontColor(UIUtil.FontColor.BRIGHTER)) + ";" +
  10. "font-family:" + descriptionFont.getFamily() + ";" +
  11. "font-size:" + descriptionFont.getSize() + "pt;}");
  12. result.setHighlighter(null);
  13. result.setEditorKit(editorKit);
  14. return result;
  15. }
  16. }

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

  1. public JRichTextPane()
  2. {
  3. super();
  4. setHighlighter(null);
  5. setEditable(false);
  6. setOpaque(false);
  7. enableAutoLinkHandler(true);
  8. setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
  9. HTMLEditorKit ek = (HTMLEditorKit) getEditorKitForContentType("text/html");
  10. ek.getStyleSheet().addRule("a {color: #DDDDDD }");
  11. }

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

  1. /**
  2. * Sets the default font for an HTML document (e.g., in a tool tip
  3. * displaying HTML). This is here because when rendering HTML,
  4. * {@code setFont()} is not honored.
  5. *
  6. * @param doc The document to modify.
  7. * @param font The font to use.
  8. * @param fg The default foreground color.
  9. */
  10. public static void setFont(HTMLDocument doc, Font font, Color fg) {
  11. doc.getStyleSheet().addRule(
  12. "body { font-family: " + font.getFamily() +
  13. "; font-size: " + font.getSize() + "pt" +
  14. "; color: " + HtmlUtil.getHexString(fg) + "; }");
  15. }

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

  1. int size = f.getSize();
  2. try {
  3. css2.addRule(new StringBuffer("body { font-size: ").append(size) // NOI18N
  4. .append("; font-family: ").append(f.getName()).append("; }").toString()); // NOI18N
  5. css2.addStyleSheet(css);

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

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

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

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

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

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

代码示例来源:origin: SonarSource/sonarlint-intellij

  1. public SonarLintRulePanel(Project project, ProjectBindingManager projectBindingManager) {
  2. this.project = project;
  3. this.projectBindingManager = projectBindingManager;
  4. this.kit = new CustomHTMLEditorKit();
  5. StyleSheet styleSheet = kit.getStyleSheet();
  6. styleSheet.addRule("td {align:center;}");
  7. styleSheet.addRule("td.pad {padding: 0px 10px 0px 0px;}");
  8. panel = new JPanel(new BorderLayout());
  9. panel.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT));
  10. setRuleKey(null);
  11. show();
  12. }

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

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

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

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

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

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

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

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

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

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

代码示例来源:origin: senbox-org/snap-desktop

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

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

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

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

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

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

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

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

  1. private void updateStyle(@NotNull JEditorPane pane) {
  2. EditorKit kit = pane.getEditorKit();
  3. if (kit instanceof HTMLEditorKit) {
  4. StyleSheet css = ((HTMLEditorKit)kit).getStyleSheet();
  5. css.addRule("body, p {" +
  6. "color:#" + ColorUtil.toHex(getForeground()) + ";" +
  7. "font-family:" + getFont().getFamily() + ";" +
  8. "font-size:" + getFont().getSize() + "pt;" +
  9. "white-space:nowrap;}");
  10. }
  11. }
  12. }

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

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

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

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

相关文章