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

This code example shows how to use the following methods:createDefaultDocument, read
    /** 
     * Given some html, extracts its text. 
     */ 
    public static String extractTextFromHTML(final String html) {
        try { 
            final EditorKit kit = new HTMLEditorKit();
            final Document doc = kit.createDefaultDocument();
 
            // The Document class does not yet handle charset's properly. 
            doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
 
            // Create a reader on the HTML content. 
            final Reader rd = new StringReader(html);
 
            // Parse the HTML. 
            kit.read(rd, doc, 0);
 
            // The HTML text is now stored in the document 
            return doc.getText(0, doc.getLength());
        } catch (final Exception e) {
        } 
6
CodeRank
This code example shows how to use the following methods:createDefaultDocument, read
 
	public void setText(String text)
	{ 
		//This is done so the vertical scroll bar goes back up to the top when the text is changed 
		EditorKit kit = textPane.getEditorKit();
		Document newDoc = kit.createDefaultDocument();
		try 
		{ 
			kit.read(new StringReader(text), newDoc, 0);
		} 
		catch (IOException ex)
		{ 
			throw new UnreachableError(ex);
		} 
		catch (BadLocationException ex)
		{ 
			throw new UnreachableError(ex);
		} 
		textPane.setDocument(newDoc);
	} 
5
CodeRank
This code example shows how to use the following methods:read
			String body = this.sourceFile.getBody();
			if (body == null || body.equals("")) {
				return; 
			} 
			Reader reader = new StringReader(body);
            this.editorKit.read(reader, this.document, 0);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (BadLocationException e) {
			e.printStackTrace();
		} finally { 
			this.propagationInProgress = false;
			if (this.pendingPropagSourceToDoc) {
				this.pendingPropagSourceToDoc = false;
				copySourceFileBodyToDocumentContent(); 
			} 
		} 
	} 
 
	@Override 
4
CodeRank
This code example shows how to use the following methods:write
         
        JEditorPane conversionPanel = new JEditorPane();
        EditorKit plainKit = conversionPanel.getEditorKit();
        try { 
            byteStream.reset();
            plainKit.write(byteStream, doc, 0, doc.getLength());
            byteStream.close();
        }  catch (Exception e) {
            throw new IllegalStateException("HtmlTransferable: Error encountered in string conversion: " + e);
        } 
        this.plainString = new String(byteStream.toByteArray());
    } 
     
    /** 
     * @see java.awt.datatransfer.Transferable#getTransferDataFlavors() 
     */ 
    public DataFlavor[] getTransferDataFlavors() {
        return flavors.clone();
    } 
 
3
CodeRank
See Code Examples for Java 8 EditorKit Methods: