Java 8 StyleSheet - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 StyleSheet class.

This code example shows how to use the following methods:addRule
        pane.setEditable(false);
        adaptForNimbus(pane);
 
        JosmHTMLEditorKit kit = new JosmHTMLEditorKit();
        final Font f = UIManager.getFont("Label.font");
        final StyleSheet ss = new StyleSheet();
        ss.addRule((allBold ? "html" : "strong, b") + " {" + getFontRule(f) + "}");
        ss.addRule("a {text-decoration: underline; color: blue}");
        ss.addRule("h1 {" + getFontRule(GuiHelper.getTitleFont()) + "}");
        ss.addRule("ol {margin-left: 1cm; margin-top: 0.1cm; margin-bottom: 0.2cm; list-style-type: decimal}");
        ss.addRule("ul {margin-left: 1cm; margin-top: 0.1cm; margin-bottom: 0.2cm; list-style-type: disc}");
        kit.setStyleSheet(ss);
        pane.setEditorKit(kit);
    } 
 
    /** 
     * Adapts a {@link JEditorPane} for Nimbus look and feel. 
     * See <a href="https://stackoverflow.com/q/15228336/2257172">this StackOverflow question</a>. 
     * @param pane The editor pane to adapt 
     * @since 6935 
6
CodeRank
This code example shows how to use the following methods:addRule
        setLayout(new BorderLayout());
        jepMessage = new JosmEditorPane("text/html", "");
        jepMessage.setOpaque(false);
        jepMessage.setEditable(false);
        Font f = UIManager.getFont("Label.font");
        StyleSheet ss = new StyleSheet();
        String rule = MessageFormat.format(
                "font-family: ''{0}'';font-size: {1,number}pt; font-weight: {2}; font-style: {3}", 
                f.getName(),
                f.getSize(),
                f.isBold() ? "bold" : "normal",
                        f.isItalic() ? "italic" : "normal"
        ); 
        rule = "body {" + rule + "}";
        rule = MessageFormat.format(
                "font-family: ''{0}'';font-size: {1,number}pt; font-weight: {2}; font-style: {3}", 
                f.getName(),
                f.getSize(),
                "bold", 
                f.isItalic() ? "italic" : "normal"

6
CodeRank
This code example shows how to use the following methods:addStyleSheet, loadRules
This code example shows how to use the following methods:addStyleSheet
     * @return the model 
     */ 
    public Document createDefaultDocument()
    { 
        StyleSheet styles = getStyleSheet();
        StyleSheet ss = new StyleSheet();
 
        ss.addStyleSheet(styles);
 
        HTMLDocument doc = new CustomHTMLDocument(ss);
        doc.setParser(getParser());
        doc.setAsynchronousLoadPriority(4);
        doc.setTokenThreshold(100);
        return doc;
    } 
 
    /** 
     * Gets the set of styles to be used to render HTML elements. 
     * 
     * @return A <code>StyleSheet</code> containing the default HTML element styles. 
5
CodeRank
This code example shows how to use the following methods:addRule
         * always work. Defined all of the basics just in case. @@@ 
         * IngestInboxViewer also defines styles similar to this. Consider a 
         * method that sets consistent styles for all viewers and takes font 
         * size as an argument. 
         */ 
        styleSheet.addRule("body {font-family:Arial, 'ヒラギノ角ゴ Pro W3','Hiragino Kaku Gothic Pro','メイリオ',Meiryo,'MS Pゴシック','MS PGothic',sans-serif;font-size:14pt;}"); //NON-NLS
        styleSheet.addRule("p {font-family:Arial, 'ヒラギノ角ゴ Pro W3','Hiragino Kaku Gothic Pro','メイリオ',Meiryo,'MS Pゴシック','MS PGothic',sans-serif;font-size:14pt;}"); //NON-NLS
        styleSheet.addRule("li {font-family:Arial, 'ヒラギノ角ゴ Pro W3','Hiragino Kaku Gothic Pro','メイリオ',Meiryo,'MS Pゴシック','MS PGothic',sans-serif;font-size:14pt;}"); //NON-NLS
        styleSheet.addRule("td {font-family:Arial, 'ヒラギノ角ゴ Pro W3','Hiragino Kaku Gothic Pro','メイリオ',Meiryo,'MS Pゴシック','MS PGothic',sans-serif;font-size:14pt;overflow:hidden;padding-right:5px;padding-left:5px;}"); //NON-NLS
        styleSheet.addRule("th {font-family:Arial, 'ヒラギノ角ゴ Pro W3','Hiragino Kaku Gothic Pro','メイリオ',Meiryo,'MS Pゴシック','MS PGothic',sans-serif;font-size:14pt;overflow:hidden;padding-right:5px;padding-left:5px;font-weight:bold;}"); //NON-NLS
        styleSheet.addRule("p {font-family:Arial, 'ヒラギノ角ゴ Pro W3','Hiragino Kaku Gothic Pro','メイリオ',Meiryo,'MS Pゴシック','MS PGothic',sans-serif;font-size:14pt;}"); //NON-NLS
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getFontMetrics
 
    /** 
     * Returns the width of the message in the given font. 
     */ 
    public static int getPixelWidth(String text, Font font) {
        StyleSheet css = new StyleSheet();
        FontMetrics fontMetrics = css.getFontMetrics(font);
        return fontMetrics.stringWidth(text);
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getFontMetrics
    /** 
     * Returns the width of the message in the given font and editor kit. 
     */ 
    private int getAverageCharacterWidthInString(String text, Font font) {
        //TODO optimize 
        StyleSheet css = new StyleSheet();
        FontMetrics fontMetrics = css.getFontMetrics(font);
        int averageCharacterWidthForFont = (int)Math.ceil((fontMetrics.stringWidth(text) /(double) text.length()));
        return averageCharacterWidthForFont;
    } 
} 
5
CodeRank
This code example shows how to use the following methods:addStyleSheet, removeStyleSheet
     * @param font must not be null  
     */ 
    public void setHtmlFont(Font font) {
        htmlFont = font;
        if (fontStyle != null) {
            mainStyle.removeStyleSheet(fontStyle);
        } 
        fontStyle = new StyleSheet();
        fontStyle.addRule(createCSS(font));
        mainStyle.addStyleSheet(fontStyle);
    } 
     
    /** 
     * Sets the foreground color of the HTML text. 
     * @param color must not be null 
     */ 
    public void setHtmlForeground(Color color) {
        htmlFontColor = color;
        if (colorStyle != null) {
            mainStyle.removeStyleSheet(colorStyle);
5
CodeRank
This code example shows how to use the following methods:removeStyle
		final LinkMouseListener linkMouseListener = new LinkMouseListener();
		tip.addMouseListener(linkMouseListener);
		tip.addMouseMotionListener(linkMouseListener);
		final HTMLDocument document = (HTMLDocument) tip.getDocument();
		final StyleSheet styleSheet = document.getStyleSheet();
		styleSheet.removeStyle("p");
		styleSheet.removeStyle("body");
		styleSheet.addRule("p {margin-top:0;}\n");
 
		final JRestrictedSizeScrollPane scrollPane = new JRestrictedSizeScrollPane(tip);
		scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		scrollPane.setMaximumSize(new Dimension(Integer.MAX_VALUE, maximumWidth / 2));
		scrollPane.addComponentListener(new ComponentAdapter() {
			@Override 
            public void componentResized(ComponentEvent e) {
	            revalidate();
            } 
		}); 
		UITools.setScrollbarIncrement(scrollPane);
4
CodeRank
This code example shows how to use the following methods:addRule, addStyleSheet
            this.platformHome.setText (new File(URI.create(((URL)installFolders.iterator().next()).toExternalForm())).getAbsolutePath());
        } 
        HTMLEditorKit htmlkit = new HTMLEditorKit();                
        StyleSheet css = htmlkit.getStyleSheet();
        if (css.getStyleSheets() == null) {
            StyleSheet css2 = new StyleSheet();
            Font f = jLabel1.getFont();
            css2.addRule(new StringBuffer("body { font-size: ").append(f.getSize()) // NOI18N
                .append("; font-family: ").append(f.getName()).append("; }").toString()); // NOI18N
            css2.addStyleSheet(css);
            htmlkit.setStyleSheet(css2);
        } 
        jTextPane1.setEditorKit(htmlkit);        
        jTextPane1.setText(NbBundle.getMessage(BrokenPlatformCustomizer.class,"MSG_BrokenProject"));
    } 
     
    // Variables declaration - do not modify//GEN-BEGIN:variables 
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextPane jTextPane1;
4
CodeRank
See Code Examples for Java 8 StyleSheet Methods: