Für mein beamer-tool-Projekt benötigte ich die Möglichkeit, HTML-Dokument (die sowieso lokal vorliegen) synchron in’s JEditorPane zu laden.
Dazu habe ich nach etwas Google- und Java-API-Suche folgende HTMLEditorKit-Klasse erstellt:
- import javax.swing.text.Document;
- import javax.swing.text.html.HTMLDocument;
- import javax.swing.text.html.HTMLEditorKit;
- public class SnycHTMLEditorKit extends HTMLEditorKit {
- private static final long serialVersionUID = 1L;
- @Override
- public Document createDefaultDocument() {
- HTMLDocument doc = (HTMLDocument)super.createDefaultDocument();
- doc.setAsynchronousLoadPriority(-1);
- return doc;
- }
- }
/*…*/
Genutzt wird das ganze dann so:
- /*...*/
- /* create jeditorpane with own editorkit */
- JEditorPane ep = new JEditorPane();
- ep.setEditorKit(new SnycHTMLEditorKit());
- /* loads page synchronous */
- ep.setPage( url );
- /*...*/
Dies funktioniert auch nach ersten Tests ohne Probleme.
Eine schöne Lösung wie ich auch finde.