JEditorPane is a component in Swing that can be used to render HTML (Hypertext Markup Language) or RTF (Rich Text Format). JEditorPane can use HTMLEditorKit as its plug-in EditorKit. HTMLEditorKit is not a GUI (Graphic User Interface) component in its own right. JEditorPane allows display of formatted HTML or RTF with colours and fonts whereas JTextPane is like JEditorPane but with the additional ability to edit styles and character attributes.
Without any coding, with AWT, the user can select, copy and paste, even in an unsigned Applet. However, Applets must be signed for copy/paste to work in Swing. Copy/paste works in Swing without signing for applications.
JEditorPane needs perfect, validated, simple HTML. Don’t try to feed it wild HTML you screenscrape from websites on the net, e.g. HTML with unbalanced tags, broken links… The JVM (Java Virtual Machine) will just hang. Only use it for rendering HTML you have generated yourself, ideally programmatically so you can be sure it contains no errors.
JEditorPane is simpler than the documentation suggests. You don’t need to get involved with Document structure. You can simply feed it raw HTML text. If you don’t embed the JEditorPane in a JScrollPane, the screen will twitch, a bug in Swing. You would think JEditorPane would be a subclass of JTextPane, but it is the reverse. In the constructor, or it setContentType pass it text/plain.
If you want to embed HTML formatting, (e.g. <u>…</u> to underline) do a setContentType( text/html ) and a setText with your text sandwiched in <html><body>…</body></html>.
JEditorPane.getText() will give you the HTML text indented and tidied with the DOCTYPE stripped off.
This page is posted
Optional Replicator mirror
Your face IP:[126.96.36.199]
You are visitor number|