Java examples for Swing:Swing HTML
get Swing Document
//package com.java2s; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import javax.swing.text.html.HTMLDocument; import javax.swing.text.html.HTMLEditorKit; import javax.swing.text.html.parser.ParserDelegator; public class Main { public static HTMLDocument getDocument(URL url) throws IOException { URLConnection connection = url.openConnection(); InputStream is = connection.getInputStream(); return getDocument(is); }//from ww w. java 2 s . co m public static HTMLDocument getDocument(InputStream is) throws IOException { InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); HTMLEditorKit htmlKit = new HTMLEditorKit(); HTMLDocument htmlDoc = (HTMLDocument) htmlKit .createDefaultDocument(); HTMLEditorKit.Parser parser = new ParserDelegator(); HTMLEditorKit.ParserCallback callback = htmlDoc.getReader(0); parser.parse(br, callback, true); return htmlDoc; } }