Using a JEditorPane to display a web page. import *; import *; import *; import *; public class. The JEditorPane class is the foundation for Swing’s styled text components and provides a mechanism Using an Editor Pane to Display Text From a URL. This class implements accessibility support for the JEditorPane class. Gets the current URL being displayed. getRef method for the URL being displayed).

Author: Fegrel Gardajin
Country: Djibouti
Language: English (Spanish)
Genre: Travel
Published (Last): 7 October 2004
Pages: 402
PDF File Size: 10.64 Mb
ePub File Size: 3.75 Mb
ISBN: 503-6-81094-162-9
Downloads: 42702
Price: Free* [*Free Regsitration Required]
Uploader: Takasa

The content type of the pane is set, and if the editor kit for the pane is non- nullthen a new default document is created and the URL is read into it. Here is the complete code: The content type that editor is bound to at any given time is determined by the EditorKit currently installed. There are multiple ways to keditorpane a character set mapping to happen with JEditorPane. Character encoding is an jeditorpae mapping of the members of a character set letters, ideographs, digits, symbols, or control functions to specific numeric code values.

Post as a guest Name. The kit used in this case is an extension of DefaultEditorKit that produces a wrapped plain text view. The default viewport layout will give the preferred size, and that is not desired in the case where the scrollable is tracking. This method will cause setDocument to be called on behalf of the caller to ensure integrity of the internal state.

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 displqy the tear down of the old view. Creates the default editor kit PlainEditorKit for when the component is first created. Fetches a stream for the given URL, which is about to be loaded by the setPage method.

How to Use Editor Panes and Text Panes

Directly sets the editor kit to use for the given type. Alternatively, to compile and run the example yourself, consult the example index. It effectively morphs into the proper kind of text editor for the kind of content it is given.


If there was no registered ClassLoaderClass. To avoid this, create a new document, getEditorKit. Note that if the content type is HTML, relative references e.

Since the calling thread can not throw an IOException in the event of failure on the other thread, the page property change event will be fired when the other thread is done whether the load was successful or not. The setPage method only supports URLs which does offer one means of achieving the desired functionality: If the content is set to a new URL, its type is used to determine the EditorKit that should be used to load the content.

The read method can be used to initialize the component from a Reader. 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.

It represents the way the file is stored. The default varies based on the look and feel; to enable it set the client property with this name to Boolean. String getContentType Gets the type of content that this editor is currently set to deal with. This is implemented to remove the contents of the current document, and replace them by parsing the given string using the current EditorKit.

Similar Threads

You can find how-to information and examples of using editor panes in Using Text Componentsa section in The Java Tutorial. This is called when a type is requested that doesn’t match the currently installed type. The document model is set to null.

Newlines For a discussion on how newlines are handled, see DefaultEditorKit. If scrolling to a reference location is needed for document types other than HTML, this method should be reimplemented. The TextSamplerDemo example barely begins to demonstrate the capabilities of editor panes and text panes.

I tried in your way, but it still doesn’t work. Fetches the editor kit to use for the given type of content. The JEditorPane class is the foundation for Swing’s styled text components and provides a mechanism through which you can add support for custom text formats.


The code uses the default constructor to create the editor pane, then calls jeditorane false so the user cannot edit the text.

Sets the currently installed kit for handling content. This has the side effect of changing the model, because the EditorKit is the source of how a particular type of content is modeled.

This method dusplay be reimplemented to use some other kind of type registry. Open a Web Page inside a jDesktopPane. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Both of those displwy can be violated and cause undesirable results.

displaying HTML in a JEditorPane (Swing / AWT / SWT forum at Coderanch)

The listener list is processed last to first. The prototype EditorKit will be loaded with Class. In order to use editor panes and text panes, you need to understand the text system, which is described in Text Component Features.

The preferred size for JEditorPane is slightly altered from the preferred size of the superclass. If this the stream was an http displqy, redirects will be followed and the resulting URL will be set as the Document.

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.

Otherwise it calls the superclass method which loads the model as plain text. To force a document reload it is necessary to clear the stream description property of the document. This is a convenience constructor that calls the setContentType and setText methods.

Giancarlo 2, 13 43 Note that the page might be loaded asynchronously, which keeps the GUI responsive but means that you should not count on the data being completely loaded after the call to setPage returns.

This method will have no effect if the component is not visible.

The base can also be set explicitly in the JEditorPane methods.