Java Swing Tutorial – Java Swing JEditorPane. A JEditorPane is a text component that can handle different text with style. By default, it can handle plain text. Did you know that you can use CSS styles when displaying HTML in a Java Swing application? It’s pretty cool, and it can help spice up any. You can use either of them, but if it is a rich text editor then I would suggest using the JTextPane. You may also find this topic useful.

Author: Dushura Tygojora
Country: Saint Lucia
Language: English (Spanish)
Genre: Environment
Published (Last): 20 September 2013
Pages: 259
PDF File Size: 15.65 Mb
ePub File Size: 3.4 Mb
ISBN: 606-7-51533-705-9
Downloads: 56506
Price: Free* [*Free Regsitration Required]
Uploader: Faugrel

JTextPane is an extension of JEditorPane which provides word processing features like fonts, text styles, colors, etc. Adds a hyperlink listener for notification of any changes, for example when a link is selected and entered.

It the file is loaded directly, the content type would be expected to have been set prior iava loading. This may load either synchronously or asynchronously depending upon the document returned by the EditorKit. An alternative way to load this component with a string would be to create a StringReader and call the read method. If the document is successfully loaded and installed, a jeditropane will be jeditprpane for it by the UI which will then be scrolled if necessary, and then the page property change event will be fired.

This’s a very technical answer, much better than the accepted one. Also see the documentation redistribution policy.


That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Although this is an interesting example that concisely demonstrates several features of JTextPane”real-world” programs aren’t likely to initialize a text pane this way. This will be established by a call to the setContentType method. Creates the default editor kit PlainEditorKit for when the component is first created.

Next, the code creates the URL object, and calls the setPage method with it. Sign up using Email and Password. In this case, the content type will be determined from the URL, and the registered EditorKit for that content type will be set. If the document is loaded asynchronously, the document will be installed into the editor immediately using a call to setDocument which will fire a document property change event, then a thread will be created which will begin doing the actual loading.

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. The class will be dynamically loaded later when actually needed using the given ClassLoaderand can be safely changed before attempted uses to avoid loading unwanted classes.

If you need a fully-fledged help system, take a look at the javahelp project. Here is the code from TextSamplerDemo. Returns true if a viewport should always force the width of this Scrollable to match the width of the viewport. This is defined to be the type associated with the currently installed EditorKit. One task that you can accomplish without knowing anything about the Swing text system is displaying text from a URL.


Sign up or log in Sign up using Google.

Java Swing Tutorial – Java Swing JEditorPane

The prototype EditorKit will be loaded with Class. Examples and practices described in this page don’t take advantage of improvements introduced in later releases.

Sachin Kumar 1 7 Using Swing Components Section: This method will cause setDocument to be called on behalf of the caller to ensure integrity of the internal state.

Next, the code loops over the arrays, inserts the text into the text pane, and specifies the style to use for the inserted text. This section introduces their capabilities, offers hints on which one you might want to use, and points to other sources of information. StreamDescriptionProperty, null ; If the desired URL is not the one currently being displayed, the getStream method is called to give subclasses control over the stream provided. The kit used in this case is the class javax.

How to add stylesheet information to a JEditorPane |

This is implemented to call JTextComponent. If there was no registered ClassLoaderClass. Provides a customized text pane.