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: Akigar Vudoshura
Country: Lebanon
Language: English (Spanish)
Genre: Sex
Published (Last): 17 October 2015
Pages: 306
PDF File Size: 16.65 Mb
ePub File Size: 1.11 Mb
ISBN: 314-9-89655-548-8
Downloads: 19740
Price: Free* [*Free Regsitration Required]
Uploader: Nikogar

String getText Returns the text contained in this TextComponent in terms of the content type of this editor. The assumption is that the previous content is relatively small, and that the previous content doesn’t have side effects. Adds a hyperlink listener for notification of any changes, for example when a link is selected and entered. Creates the default editor kit PlainEditorKit for when the component is first created.

Sets the type of content that this editor handles. This method initializes from a stream. One way is to specify the character set as a parameter of the MIME type. If this the stream was an http connection, redirects will be followed and the resulting URL jedirorpane be set as the Document.

Post Your Answer Discard By clicking “Post Your Answer”, you acknowledge that you have read our updated terms of serviceprivacy policy and cookie policyand that your continued use of the website is subject to these policies.

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

Here we list the facts again and provide a bit more detail. The default viewport layout will give the preferred size, and that is not desired in the case where the jeditorpaen is tracking.

Java Code Examples of rPane

Leaving the existing model in place means that the old view will be torn down, and a new view created, where replacing the document would avoid the tear down of the old view. Returns the preferred size for the JEditorPane. Also see the documentation redistribution policy.


You can see an editor pane and a text pane in use by running TextSamplerDemo. This’s a very technical answer, much better than the accepted one. If the size of the viewport has become smaller than the minimum size of the component, the scrollable definition for tracking width or height will turn to false.

JTextPane is an extension of JEditorPane which provides word processing features like fonts, text styles, colors, etc. The implementation calls the scrollRectToVisible method to accomplish the actual scrolling.

Sets the current URL being displayed. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. However, the top right editor pane illustrates a handy, easy-to-use feature: IOException – as thrown by the stream being used to initialize See Also: Sets the currently installed kit for handling content.

How to Use Editor Panes and Text Panes

This section lists some of the API related to text and editor panes. Otherwise it calls the superclass method which loads the model as plain text. Please tell me suitable difference between these two that in which kind of situation i have to use one of these. Swing is not thread safe. A look-and-feel implementation might use this in conjunction with createEditorKitForContentType to install handlers for content types with a look-and-feel bias.

It effectively morphs into the proper kind of text editor for the kind jva content it is given. Replaces the currently selected content with new content represented by the given string.

This method will have no effect if the component is not visible. Key for a client property used to indicate jedutorpane the default font and foreground color from the component are jeditorpans if a font or foreground color is not specified in the styled text.

Java Swing Tutorial – Java Swing JEditorPane

This method can be reimplemented to use some other kind of type registry. The prototype EditorKit will be loaded with Class. Next, the code loops over the arrays, inserts the text into the text pane, and specifies the style to use for the inserted text.


Serialized objects of this class will not be compatible with future Swing releases. If you want unstyled text, use a text area instead. Newlines For a discussion on how newlines are handled, see DefaultEditorKit.

Java Swing Tutorial – Java Swing JEditorPane

Sign up using Email and Password. The TextSamplerDemo example barely begins to demonstrate the capabilities of editor panes and text panes. If the document is successfully loaded and installed, a view will be built for it by the UI which will then be scrolled if necessary, and then the page property change event will be fired.

Here is the code from TextSamplerDemo. This method will cause setDocument to be called on behalf of the caller to ensure integrity of the internal state. In this case the model would be replaced after it was initialized with the contents of the string. This is implemented to call JTextComponent. Sign up or log in Sign up using Google.

By default, this simply opens the URL and returns the stream. Creates a JEditorPane that has been initialized to the given text. By default this is not enabled; to enable it set the client jva with this name to Boolean. If the text format is known, the editor pane initializes itself with the text found at the URL.

Fetches the currently installed kit for jefitorpane content. This may load either synchronously or asynchronously depending upon the document returned by the EditorKit. NullPointerException – if the type parameter is null See Also: If the component doesn’t have an EditorKit registered for the given type, it will try to create an EditorKit from the default EditorKit registry.