J Editor Pane

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 5

JEditorPane

Bhakti Sawant
5631
JEditorpane is a form of text area that can display different text formats.
JEditorPane is used for creating a simple text editor window.
Syntax:-public class JEditorPane extends JTextComponent
Its class has two methods:-
o setContentType()- Used to set the content type to be plain text.
o setText()- Used to set the initial text content.

JEditorPane supports RTF and HTML by default.


The content for JEditorPane can be set by passing URL
object into its constructor,using setpage() to set
content at runtime, passing content as a string to
setText(), using read and by supplying an
HTMLDocument object with Inputstream object.
There are 3 types of content used by JEditorPane:
1. text/plain(default)
2. text/HTML(javax.swing.text.html.HTMLEditorkit)
3. text/RTF(javax.swing.text.rtf.RTFEditorkit)

The constructors of JEditorPane are JEditorPane(),


JEditorPane(String URL), JEditorPane(URL initial page),
JEditorPane(String type, String text.

The methods useful for JEditorPane class :


void setText(String text) – Sets text
void getText()- Return the text of the component
void setPage(URL page)- Shows specified URL as the current page
Void setContentType(String type)-sets type of the content
void addHyperlinkListener(HyperlinkListener listener)- adds a
hyperlink listener to the component.
Example-
import javax.swing.JEditorPane;  
import javax.swing.JFrame;  
public class JEditorPaneExample {  
    JFrame myFrame = null;  
    public static void main(String[] a) {  
        (new JEditorPaneExample()).test();  
    }  
    private void test() {  
        myFrame = new JFrame("JEditorPane Test");  
        myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
        myFrame.setSize(400, 200);  
        JEditorPane myPane = new JEditorPane();  
        myPane.setContentType("text/plain");  
        myPane.setText(“A text to edit various kinds of content."  
                + “By default,JEditorPane supports HTML and RTF."  
                + " Sets the content type to be plain text.");  
        myFrame.setContentPane(myPane);  
        myFrame.setVisible(true);  
    }  
}  
Thank You

You might also like