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

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

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

  1. public FixedHeightPane () {
  2. super ();
  3. setEditable(false);
  4. HTMLEditorKit htmlkit = new HTMLEditorKit();
  5. StyleSheet css = htmlkit.getStyleSheet();
  6. if (css.getStyleSheets() == null) {
  7. StyleSheet css2 = new StyleSheet();
  8. Font f = new JList().getFont();
  9. int size = f.getSize();
  10. try {
  11. css2.addRule(new StringBuffer("body { font-size: ").append(size) // NOI18N
  12. .append("; font-family: ").append(f.getName()).append("; }").toString()); // NOI18N
  13. css2.addStyleSheet(css);
  14. htmlkit.setStyleSheet(css2);
  15. } catch( RuntimeException ex ) {

代码示例来源: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.codehaus.jtstand/jtstand-desktop

  1. /**
  2. * Sets the font used for HTML displays to the specified font. Components
  3. * that display HTML do not necessarily honor font properties, since the
  4. * HTML document can override these values. Calling {@code setHtmlFont}
  5. * after the data is set will force the HTML display to use the font
  6. * specified to this method.
  7. *
  8. * @param doc
  9. * the HTML document to update
  10. * @param font
  11. * the font to use
  12. * @throws NullPointerException
  13. * if any parameter is {@code null}
  14. */
  15. public static void setHtmlFont(HTMLDocument doc, Font font) {
  16. String stylesheet = String.format(STYLESHEET, font.getName(),
  17. font.getSize(), font.getName(), font.getSize());
  18. try {
  19. doc.getStyleSheet().loadRules(new StringReader(stylesheet), null);
  20. } catch (IOException e) {
  21. //this should never happen with our sheet
  22. throw new IllegalStateException(e);
  23. }
  24. }

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

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

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

  1. @Override
  2. public void setFont(Font font) {
  3. super.setFont(font);
  4. Document doc = getDocument();
  5. if (!(doc instanceof HTMLDocument)) {
  6. return;
  7. }
  8. StyleSheet styleSheet = ((HTMLDocument) doc).getStyleSheet();
  9. styleSheet.addRule("body { font-family: " + font.getName() + "; "
  10. + " font-size: " + font.getSize() + "; "
  11. + " font-style: " + (font.getStyle() == Font.BOLD ? "bold"
  12. : font.getStyle() == Font.ITALIC ? "italic" : "normal") + "; "
  13. + " color: " + EditorColor.COLOR_FOREGROUND.toHex() + "; "
  14. + " background: " + EditorColor.COLOR_BACKGROUND.toHex() + "; "
  15. + " }");
  16. }

代码示例来源: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: JetBrains/jediterm

  1. public static HTMLEditorKit getHTMLEditorKit(boolean noGapsBetweenParagraphs) {
  2. Font font = getLabelFont();
  3. @NonNls String family = !SystemInfo.isWindows && font != null ? font.getFamily() : "Tahoma";
  4. int size = font != null ? font.getSize() : JBUI.scale(11);
  5. String customCss = String.format("body, div, p { font-family: %s; font-size: %s; }", family, size);
  6. if (noGapsBetweenParagraphs) {
  7. customCss += " p { margin-top: 0; }";
  8. }
  9. final StyleSheet style = new StyleSheet();
  10. style.addStyleSheet(isUnderDarcula() ? (StyleSheet) UIManager.getDefaults().get("StyledEditorKit.JBDefaultStyle") : DEFAULT_HTML_KIT_CSS);
  11. style.addRule(customCss);
  12. return new HTMLEditorKit() {
  13. @Override
  14. public StyleSheet getStyleSheet() {
  15. return style;
  16. }
  17. };
  18. }

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

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

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

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

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

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

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

  1. /**
  2. * Overriden to return our own slimmed down style sheet.
  3. */
  4. public StyleSheet getStyleSheet() {
  5. if (defaultStyles == null) {
  6. defaultStyles = new StyleSheet();
  7. StringReader r = new StringReader(ScaledHTML.styleChanges);
  8. try {
  9. defaultStyles.loadRules(r, null);
  10. }
  11. catch (Throwable e) {
  12. // don't want to die in static initialization...
  13. // just display things wrong.
  14. }
  15. r.close();
  16. defaultStyles.addStyleSheet(super.getStyleSheet());
  17. }
  18. return defaultStyles;
  19. }

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

  1. final HTMLDocument hd=(HTMLDocument)kit_.createDefaultDocument();
  2. kit_.read(new StringReader(_source),hd,0);
  3. hd.setBase(_url);
  4. hd.putProperty("IgnoreCharsetDirective",Boolean.TRUE);
  5. kit_.read
  6. (new InputStreamReader
  7. (getInputStreamFor(_url),"iso-8859-1"),hd,0);
  8. updateStyles(hd.getStyleSheet());
  9. StyleSheet ss=hd.getStyleSheet();
  10. StyleSheet[] as=ss.getStyleSheets();
  11. if(as!=null)
  12. for(int i=0;i<as.length;i++)
  13. ss.removeStyleSheet(as[i]);
  14. Enumeration rules=ss.getStyleNames();
  15. while (rules.hasMoreElements())
  16. ss.removeStyle(name);

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

  1. String htmlString = "<body><h1>Karaoke Beyonce song</h1><p><span class="highlight">Hello</span>world</p></body>";
  2. JEditorPane pane = new JEditorPane();
  3. HTMLEditorKit kit = new HTMLEditorKit();
  4. pane.setEditable(false);
  5. pane.setEditorKit(kit);
  6. StyleSheet sh = editorKit.getStyleSheet();
  7. sh.addRule("span.highlight {background-color:yellow}");
  8. Document doc = kit.createDefaultDocument();
  9. pane.setDocument(doc);
  10. pane.setText(htmlString);

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

  1. public Document createDefaultDocument(JLabel c) {
  2. Font font = c.getFont();
  3. Color foreground = c.getForeground();
  4. StyleSheet styles = getStyleSheet();
  5. StyleSheet ss = new ScaledStyleSheet();
  6. ss.addStyleSheet(styles);
  7. HTMLDocument doc = new HTMLDocument(ss);
  8. doc.setPreservesUnknownTags(false);
  9. doc.getStyleSheet().addRule(new StringBuffer("body {").append(new CssRuleBuilder()
  10. .withCSSFont(font, UITools.FONT_SCALE_FACTOR)
  11. .withColor(foreground)
  12. .withAlignment(c.getHorizontalAlignment())).append("}").toString());
  13. doc.setParser(getParser());
  14. doc.setAsynchronousLoadPriority(Integer.MAX_VALUE);
  15. doc.setPreservesUnknownTags(false);
  16. return doc;
  17. }
  18. }

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

  1. private void setTipTextUnsafe(String tipText) throws Exception{
  2. tip.setSize(0, 0);
  3. tip.setPreferredSize(null);
  4. tip.setText(tipText);
  5. ((HTMLDocument)tip.getDocument()).setBase(baseUrl);
  6. Dimension preferredSize = tip.getPreferredSize();
  7. if (preferredSize.width > maximumWidth && contentType.equals(FreeplaneTooltip.TEXT_HTML)) {
  8. final HTMLDocument document = (HTMLDocument) tip.getDocument();
  9. document.getStyleSheet().addRule("body { width: " + maximumWidth + "}");
  10. // bad hack: call "setEditable" only to update view
  11. tip.setEditable(true);
  12. tip.setEditable(false);
  13. preferredSize = tip.getPreferredSize();
  14. if (preferredSize.width > maximumWidth) {
  15. }
  16. }
  17. tip.setSize(preferredSize);
  18. preferredSize = tip.getPreferredSize();
  19. tip.setPreferredSize(preferredSize);
  20. }

相关文章