Java JEditorPane

JEditorPane class is used to create a simple text editor window. This class has setContentType() and setText() methods.

setContentType("text/plain"): This method is used to set the content type to be plain text.

setText(text): This method is used to set the initial text content.

Nested Classes

Modifier and TypeClassDescription
protected classJEditorPane.AccessibleJEditorPaneThis class implements accessibility support for the JEditorPane class.
protected classJEditorPane.AccessibleJEditorPaneHTMLThis class provides support for AccessibleHypertext, and is used in instances where the EditorKit installed in this JEditorPane is an instance of HTMLEditorKit.
protected classJEditorPane.JEditorPaneAccessibleHypertextSupportWhat's returned by AccessibleJEditorPaneHTML.getAccessibleText

Fields

Modifier and TypeFieldDescription
static StringHONOR_DISPLAY_PROPERTIESKey for a client property used to indicate whether the default font and foreground color from the component are used if a font or foreground color is not specified in the styled text.
static StringW3C_LENGTH_UNITSKey for a client property used to indicate whether w3c compliant length units are used for html rendering.

Constructors

ConstructorDescription
JEditorPane()It creates a new JEditorPane.
JEditorPane(String url)It creates a JEditorPane based on a string containing a URL specification.
JEditorPane(String type, String text)It creates a JEditorPane that has been initialized to the given text.
JEditorPane(URL initialPage)It creates a JEditorPane based on a specified URL for input.

Useful Methods

Modifier and TypeMethodDescription
voidaddHyperlinkListener(HyperlinkListener listener)Adds a hyperlink listener for notification of any changes, for example when a link is selected and entered.
protected EditorKitcreateDefaultEditorKit()It creates the default editor kit (PlainEditorKit) for when the component is first created.
voidsetText(String t)It sets the text of this TextComponent to the specified content, which is expected to be in the format of the content type of this editor.
voidsetContentType(String type)It sets the type of content that this editor handles.
voidsetPage(URL page)It sets the current URL being displayed.
voidread(InputStream in, Object desc)This method initializes from a stream.
voidscrollToReference(String reference)It scrolls the view to the given reference location (that is, the value returned by the UL.getRef method for the URL being displayed).
voidsetText(String t)It sets the text of this TextComponent to the specified content, which is expected to be in the format of the content type of this editor.
StringgetText()It returns the text contained in this TextComponent in terms of the content type of this editor.
voidread(InputStream in, Object desc)This method initializes from a stream.

JEditorPane Example

Output:

Java JEditorpane

JEditorPane Example: using HTML

Output:

Java JEditorpane 2




Latest Courses