Difference between JEditorPane and JTextPane

Difference between JTextPane and JEditorPane

Before looking at difference between JEditorPane and JTextPane we need to look at from where they are derived. JEditorPane and JTextPane both are inherited from javax.swing.text.JTextComponent and JTextPane is specialized form of JEditorPane as JTextPane is inherited from JEditorPane. So we can say JTextPane is specialized form of JEditorPane with some extra powers. Now lets look at difference between JTextPane and JEditorPane in detail.

As we know JEditorPane or a JTextPane can easily be loaded with text from a URL using a setPage method. But diference between two is you can initialize the JEditorPane from a URL using constructor,
this is not the case with JTextPane. You need to use setPage in this case.

JTextPane needs a document which should implement the StyledDocument interface. Even though an editor pane is a styled text component, by default it uses an instance of PlainDocument. But in case of standard JTextPane The default document is an instance of DefaultStyledDocument. DefaultStyledDocument is a a container for styled text in no particular format and can be marked up with character and paragraph styles in a manner similar to the RTF.

And HTML and RTF document works well in JTextPane as it uses HTMLDocument and RTFDocument both implements StyledDocument interface.
As we know for supporting a custom text format,JEditorPane and JTextPane implement an editor kit that can read, write, and edit text of that custom format. But JTextPane needs its editor kit be an instance of a StyledEditorKit or a subclass of StyledEditorKit unlike the JEditorPane.
When we want to embed images and components, JTextPane API provides lot of methods to do this. You can embed images and components in JEditorPane too but you need to include images in HTML or RTF.

Thus we have seen the difference between JEditorPane and JTextPane, if you want to share more you can share it via comments also if you like this article share with your friends.
Share on Google Plus

About Pranav

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment


Post a Comment