Java 8 DefaultStyledDocument - 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 DefaultStyledDocument class.

This code example shows how to use the following methods:addStyle, getStyle, setBase
        tfText.setText(StringUtils.excerpt(aText, EXCERPT_SENTENCES, EXCERPT_MIN_CHARS, EXCERPT_MAX_CHARS));
        tfText.setEditable(false);
        tfText.setToolTipText("<html>" + aText);
 
        HTMLDocument doc = (HTMLDocument)tfText.getDocument();
        doc.setBase(article.getLink());
        Style def = doc.getStyle("default");
        doc.addStyle(TEXT_STYLE_NAME, def);
        UifUtilities.setFontAttributes(doc, TEXT_STYLE_NAME, articleConfig.getTextFont());
 
        setViewMode(config.getViewMode());
 
        layout = new FormLayout("5px, center:pref, 5px", "5px, pref, 5px, pref, 5px, pref, 5px");
        setLayout(layout);
 
        aImageURL = aImageURL == null ? config.getNoImageURL() : aImageURL;
        Dimension dim = modeToDimension(config.getViewMode());
        lbImage = new AsyncImagePanel(aImageURL, dim.width, dim.height,
            new ShadowBorder(COLOR_SHADOW_BORDER), article.isRead());
        setTextComponentsWidth(); 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setDocumentFilter, addDocumentListener
  public static JTextArea newReadOnlyLengthLimitedTextArea(DocumentListener listener, int rows, int columns) {
 
    JTextArea textArea = newReadOnlyTextArea(rows, columns);
 
    // Limit the length of the underlying document 
    DefaultStyledDocument doc = new DefaultStyledDocument();
    doc.setDocumentFilter(new DocumentMaxLengthFilter(rows * columns));
    textArea.setDocument(doc);
 
    // Ensure we monitor changes 
    doc.addDocumentListener(listener);
 
    return textArea;
 
  } 
 
  /** 
   * @return A new "enter transaction label" text field 
   */ 
  public static JTextField newEnterTransactionLabel() {
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:putProperty, insertString
     * 
     * @throws javax.swing.text.BadLocationException 
     */ 
    @Test
    public void testGetIndentString() throws BadLocationException {
        DefaultStyledDocument document = new DefaultStyledDocument();
        document.putProperty(Language.class, MarkdownTokenId.language());
        document.insertString(0, "    * list\n", null); // white space
        String result = MarkdownDocUtil.getIndentString(document, 10);
        assertEquals("    ", result);
 
        document.insertString(0, "	* list\n", null); // tab space
        result = MarkdownDocUtil.getIndentString(document, 7);
        assertEquals("	", result);
 
        document.insertString(0, "  	  * list\n", null); // white space and tab space
        result = MarkdownDocUtil.getIndentString(document, 11);
        assertEquals("  	  ", result);
 
        document.insertString(0, "* list\n", null); // no indent

4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
    private boolean wrap;
 
    public StyledTextArea() { 
        super(); 
 
        doc = new DefaultStyledDocument();
        setDocument( doc );
 
        setEditable( false );
        Style defStyle = StyleContext.getDefaultStyleContext()
                                     .getStyle( StyleContext.DEFAULT_STYLE );
 
        /* Set up some styles. */ 
        Style normalStyle = addStyle( "normal", defStyle );
        StyleConstants.setFontFamily( normalStyle, "Bitstream Charter" );
 
        Style titleStyle = addStyle( "title", normalStyle );
        StyleConstants.setUnderline( titleStyle, true );
        StyleConstants.setFontSize( titleStyle,
                                    StyleConstants
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getDefaultRootElement
This code example shows how to use the following methods:
     
    /** The StyleContext for the Console. */ 
    ConsoleStyleContext styleContext = new ConsoleStyleContext();
     
    /** The text area to which everything is written. */ 
    JTextPane textArea = new JTextPane(new DefaultStyledDocument(styleContext));
 
    /** 
     * Creates a new Console object. 
     * @throws IOException 
     */ 
    private Console() throws IOException {
    	// Set up Custom 
    	piCustom = new PipedInputStream();
    	poCustom = new PipedOutputStream();
        printStream = new PrintStream(poCustom);
    	 
        // Set up System.out 
        piOut = new PipedInputStream();
        poOut = new PipedOutputStream(piOut);
3
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getCharacterElement
        int pos = editor.viewToModel(pt);
        if (pos >= 0) {
            Document doc = editor.getDocument();
            if (doc instanceof DefaultStyledDocument) {
                DefaultStyledDocument hdoc = (DefaultStyledDocument) doc;
                Element el = hdoc.getCharacterElement(pos);
                AttributeSet a = el.getAttributes();
                String href = (String) a.getAttribute(HTML.Attribute.HREF);
                if (href != null) {
                    try { 
                        Desktop desktop = Desktop.getDesktop();
                        URI uri = new URI(href);
                        desktop.browse(uri);
                    } catch (Exception ev) {
                        GUIMain.log((ev.getMessage()));
                    } 
                } 
            } 
        } 
        super.mouseReleased(e);
3
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
    	 this.setEditable(true);
    	this.setPreferredSize(new Dimension(550,500));
		this.setContentType("text/java");
		this.setText("");
		 
		doc = new DefaultStyledDocument();/* {
            public void insertString (int offset, String str, AttributeSet a) throws BadLocationException { 
                super.insertString(offset, str, a); 
 
                String text = getText(0, getLength()); 
                int before = findLastNonWordChar(text, offset); 
                if (before < 0) before = 0; 
                int after = findFirstNonWordChar(text, offset + str.length()); 
                int wordL = before; 
                int wordR = before; 
 
                while (wordR <= after) { 
                    if (wordR == after || String.valueOf(text.charAt(wordR)).matches("\\W")) { 
                        if (text.substring(wordL, wordR).matches("(\\W)*(private|public|protected)")) 
                            setCharacterAttributes(wordL, wordR - wordL, attr, false); 
2
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Java 8 DefaultStyledDocument Methods: