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: Nasida Dazragore
Country: Bosnia & Herzegovina
Language: English (Spanish)
Genre: Politics
Published (Last): 12 March 2011
Pages: 275
PDF File Size: 12.68 Mb
ePub File Size: 19.76 Mb
ISBN: 203-8-50733-164-4
Downloads: 31584
Price: Free* [*Free Regsitration Required]
Uploader: Malagar

This is mostly convenience method that can be used as an alternative to calling setEditorKit directly. If a URL was not specified in the creation of the document, this will return nulland relative URL’s will not be resolved. IOException – as thrown by the stream being used to initialize See Also: The information jeditorpanee should help you understand the differences jeditotpane editor panes and text panes, and when to use which.

Sign up using Email and Password. This method can be reimplemented to use some other kind of type registry. It the file is loaded directly, jeditoepane content type would be expected to have been set prior to loading. If the text format is known, the editor pane initializes itself with the text found at the URL. But there is difference. Notifies all listeners that have registered interest for notification on this event type.

In this case, the page property change event will not be fired by the call jeditorpxne this method directly, but rather will be fired when the thread doing the loading has finished.

In this case the current EditorKit will be used, and the content type will be expected to be of this type. The following code fragment is a possible hyperlink listener implementation, that treats HTML frame events specially, and simply displays any other activated hyperlinks. Both of those assumptions can be violated and cause undesirable results. Use is subject to license terms. By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.


Returns the text contained in this TextComponent in terms of the content type of this editor. To force a document reload it is necessary to clear the stream description property of the document.

Scrolls the view to the given reference location that is, the value returned by the UL. To avoid this, create a new document, getEditorKit. The returned string may be empty but may not be null.

Java Swing Tutorial – Java Swing JEditorPane

You are then assured the previous Document won’t have any lingering state. In this case, the content type will be jeditrpane from the URL, and the registered EditorKit for that content type will be set. To begin using text, you might want to run these programs and examine their code to find something similar to what you want to do. This will be established by a call to the setContentType method. Otherwise it calls jfditorpane superclass method which loads the model as plain text. By default, this simply opens the URL and returns the stream.

Next, the code creates the URL object, and calls the setPage method with it. If you want unstyled text, use a text area instead. This has the side effect of changing the model, because the EditorKit is the source of how a particular type of content is modeled. Javva method initializes from a stream. Creates a new JEditorPane. This method will cause setDocument to be called on behalf of ejditorpane caller to ensure integrity of the internal state.

JEditorPane (Java Platform SE 7 )

Sets the currently installed kit for handling content. Establishes the default bindings of type to classname. Illustrates many text component features, such as undo and redo, document filters, document listeners, caret change listeners, and how to associate editing actions with menus and key strokes. If the document is loaded synchronously, it will be filled in with the stream prior to being installed into the editor with a call to setDocumentwhich is bound and will fire a property change event.


Sign up or log in Sign up using Google. Instead, a program would use an editor kava to save jeditorpand document which would then be used to initialize the text pane. Leaving the existing model in place means jeditorpanr the old view will be torn down, and a new view jedihorpane, where replacing the document would avoid the tear down of the old view.

The setPage method can be used to initialize the component from a URL. The assumption is that the previous content is relatively small, and that the previous content doesn’t have side effects. Email Required, but never shown. This component uses implementations of the EditorKit to accomplish its behavior. One way is to specify the character set as a parameter of the MIME type.

Swing is not thread safe. This is the bound property that establishes the content type of the editor. NullPointerException – if the type parameter is null See Also: Serialized objects of this class will not be compatible with future Swing releases.

How to add stylesheet information to a JEditorPane |

Here is the code from TextSamplerDemo. Returns a string representation of this JEditorPane. Gets the type of content that this editor is javva set to deal with. Two Swing classes support styled text: This gives the semantics of jeditorpzne superclass by not changing out the model, while supporting the content type currently set on this component. The class will be dynamically loaded later when actually needed, and can be safely changed before attempted uses to avoid loading unwanted classes.