Here is the code from TextSamplerDemo. Next, the code creates the URL object, and calls the setPage method with it. If the text format is known, the editor pane initializes itself with the text found at the URL. 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.
|Published (Last):||10 May 2013|
|PDF File Size:||18.52 Mb|
|ePub File Size:||3.73 Mb|
|Price:||Free* [*Free Regsitration Required]|
You can find how-to information and examples of using editor panes in Using Text Components , a section in The Java Tutorial. This component uses implementations of the EditorKit to accomplish its behavior. It effectively morphs into the proper kind of text editor for the kind of content it is given.
The content type that editor is bound to at any given time is determined by the EditorKit currently installed. 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 kit used in this case is an extension of DefaultEditorKit that produces a wrapped plain text view. The kit used in this case is the class javax.
There are several ways to load content into this component. The setText method can be used to initialize the component from a string. In this case the current EditorKit will be used, and the content type will be expected to be of this type. The read method can be used to initialize the component from a Reader. Note that if the content type is HTML, relative references e. The setPage method can be used to initialize the component from a URL. In this case, the content type will be determined from the URL, and the registered EditorKit for that content type will be set.
Some kinds of content may provide hyperlink support by generating hyperlink events. If HTML frames are embedded in the document, the typical response would be to change a portion of the current document. The following code fragment is a possible hyperlink listener implementation, that treats HTML frame events specially, and simply displays any other activated hyperlinks.
Character encoding is an unambiguous mapping of the members of a character set letters, ideographs, digits, symbols, or control functions to specific numeric code values. It represents the way the file is stored. There are multiple ways to get a character set mapping to happen with JEditorPane.
One way is to specify the character set as a parameter of the MIME type. This will be established by a call to the setContentType method. If the content is loaded by the setPage method the content type will have been set according to the specification of the URL. It the file is loaded directly, the content type would be expected to have been set prior to loading. Another way the character set can be specified is in the document itself. This requires reading the document prior to determining the character set that is desired.
To handle this, it is expected that the EditorKit. Newlines For a discussion on how newlines are handled, see DefaultEditorKit.
Warning: Swing is not thread safe. Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1. Please see XMLEncoder. Nested Class Summary.
Subscribe to RSS
Swing Examples - Using JEditorPane to display an HTML page