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

x33g5p2x  于2022-01-20 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(118)

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

HTMLEditorKit.getStyleSheet介绍

暂无

代码示例

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

  1. StyleSheet css = htmlkit.getStyleSheet();

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

  1. editorPane.setContentType("text/html");
  2. HTMLEditorKit kit = new HTMLEditorKit();
  3. editorPane.setEditorKit(kit);
  4. File cssfile = new File("src/Assets/code.css");
  5. StyleSheet styleSheet = kit.getStyleSheet();
  6. styleSheet.importStyleSheet(cssfile.toURI().toURL());
  7. editorPane.setText("<html><head></head><body><pre></pre></body></html>");

代码示例来源:origin: de.huxhorn.sulky/de.huxhorn.sulky.logging

  1. public static void logStyles(HTMLEditorKit htmlEditorKit)
  2. {
  3. final Logger logger = LoggerFactory.getLogger(SwingLogging.class);
  4. if(logger.isDebugEnabled())
  5. {
  6. StringBuilder msg = new StringBuilder();
  7. msg.append("Primary:\n");
  8. StyleSheet styleSheet = htmlEditorKit.getStyleSheet();
  9. appendStyles(styleSheet, msg);
  10. logger.debug(msg.toString());
  11. }
  12. }

代码示例来源:origin: huxi/sulky

  1. public static void logStyles(HTMLEditorKit htmlEditorKit)
  2. {
  3. final Logger logger = LoggerFactory.getLogger(SwingLogging.class);
  4. if(logger.isDebugEnabled())
  5. {
  6. StringBuilder msg = new StringBuilder();
  7. msg.append("Primary:\n");
  8. StyleSheet styleSheet = htmlEditorKit.getStyleSheet();
  9. appendStyles(styleSheet, msg);
  10. logger.debug(msg.toString());
  11. }
  12. }

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

  1. HTMLEditorKit kit = (HTMLEditorKit())textpane.getEditorKit(kit);
  2. StyleSheet styleSheet = kit.getStyleSheet();
  3. styleSheet.addRule(".col0 {...}");

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

  1. JEditorPane pane = new JEditorPane();
  2. String u = "C:/path/to/bullet.png";
  3. HTMLEditorKit htmlEditorKit = (HTMLEditorKit) pane.getEditorKit();
  4. StyleSheet styleSheet = htmlEditorKit.getStyleSheet();
  5. styleSheet.addRule(String.format("ul{list-style-image:url(%s);margin:0px 20px;", u));

代码示例来源:origin: nroduit/Weasis

  1. public static HTMLEditorKit buildHTMLEditorKit(JComponent component) {
  2. Objects.requireNonNull(component);
  3. HTMLEditorKit kit = new HTMLEditorKit();
  4. StyleSheet ss = kit.getStyleSheet();
  5. ss.addRule("body {font-family:sans-serif;font-size:12pt;background-color:#" //$NON-NLS-1$
  6. + Integer.toHexString((component.getBackground().getRGB() & 0xffffff) | 0x1000000).substring(1) + ";color:#" //$NON-NLS-1$
  7. + Integer.toHexString((component.getForeground().getRGB() & 0xffffff) | 0x1000000).substring(1)
  8. + ";margin:3;font-weight:normal;}"); //$NON-NLS-1$
  9. return kit;
  10. }

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mobility-cldcplatform

  1. private void postInitComponents() {
  2. final HTMLEditorKit htmlkit = new HTMLEditorKit();
  3. final StyleSheet css = htmlkit.getStyleSheet();
  4. if (css.getStyleSheets() == null) {
  5. final StyleSheet css2 = new StyleSheet();
  6. final Font f = new JLabel().getFont();
  7. css2.addRule(new StringBuffer("body { font-size: ").append(f.getSize()) // NOI18N
  8. .append("; font-family: ").append(f.getName()).append("; }").toString()); // NOI18N
  9. css2.addStyleSheet(css);
  10. htmlkit.setStyleSheet(css2);
  11. }
  12. jTextPane1.setEditorKit(htmlkit);
  13. jTextPane1.setText(NbBundle.getMessage(BrokenPlatformCustomizer.class, "MSG_BrokenProject")); // NOI18N
  14. }

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

  1. protected synchronized void updateHtml() {
  2. this.teDocument.setText(this.modelToHtml());
  3. this.editor.getStyleSheet().addRule(this.configuration.getRules());
  4. }

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

  1. /**
  2. * Overriden to return our own slimmed down style sheet.
  3. */
  4. @Override
  5. public StyleSheet getStyleSheet() {
  6. if (defaultStyles == null) {
  7. defaultStyles = new StyleSheet();
  8. StringReader r = new StringReader(styleChanges);
  9. try {
  10. defaultStyles.loadRules(r, null);
  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: 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: 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: 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: 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() + "; font-size: 12pt; font-style:normal;}");
  6. }

代码示例来源: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: 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. }

相关文章