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: Nikolar Basho
Country: Serbia
Language: English (Spanish)
Genre: Life
Published (Last): 28 May 2008
Pages: 301
PDF File Size: 20.23 Mb
ePub File Size: 19.68 Mb
ISBN: 597-3-29254-322-3
Downloads: 77469
Price: Free* [*Free Regsitration Required]
Uploader: Faeran

This is a convenience constructor that calls the setContentType and setText methods. This is normally called by the currently installed EditorKit if a content type that supports hyperlinks is currently active and there was activity with a link.

A look-and-feel implementation might use this in conjunction with createEditorKitForContentType to install handlers for content types with a look-and-feel bias.

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. Here we list the facts again and provide a bit more detail. You have to provide type, and get the resource. If HTML frames are embedded in the document, the typical response would be to change a portion of the current document.

I’ve already tried this way and I ever get a null pointer exception: The class neditorpane be dynamically loaded later when actually needed, and can be safely changed before attempted uses to avoid loading unwanted classes. Several facts about editor panes and text panes are scattered throughout that section. Creates a JEditorPane that has jditorpane initialized to the given dispay.

Java Tutorial – Display html string in JEditorPane in Java

If your program uses the setPage method, make sure you adjust your code for possible changes to the pane’s document and editor kit instances re-register document listeners on the new document, and so on. In this case the model would be replaced after it was initialized with the contents of the string. The content type of the pane is set, and if the editor kit for jedihorpane pane is non- nullthen a new default document is created and the URL is read into it.


Glad I could help! That documentation contains more detailed, developer-targeted descriptions, dusplay conceptual overviews, definitions of terms, workarounds, and working code examples. The implementation calls the scrollRectToVisible method to accomplish the actual scrolling.

If there is no replacement text i. It represents the way the file is stored. May I ask what ojbect you use to call showPage String dispoay An alternative way to load this component with a string would be to create a StringReader and call the read method. Leaving the existing model in place means that the old view will be torn jeditoprane, and a new view created, where replacing the document would avoid the tear down of the old view.

Sets the currently installed kit for handling content. In order to use editor panes and text panes, you need to understand the text system, which is described in Text Component Features. This method can be reimplemented to use some other kind of type registry. Otherwise it calls the superclass method jeditorpanf loads the model as plain text. The prototype EditorKit will be loaded with Class.

In this case the current EditorKit will be used, and the dispaly type will be expected to be of this type.

Replaces the currently selected content with new content represented by the given string. Next, the code creates the URL object, and calls the setPage method with it.

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

I think a little modification if the program jedditorpane run outside of netbeans. Could you please tell me how you define the String page here? 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. This method will cause setDocument to be called on behalf of the caller to ensure integrity of the internal state. Scrolls the view to the given reference location that is, the value returned by the UL.


Instead, a program would use an editor pane to save a document which would then be used to initialize the text pane. How to Make Dialogs Next page: StreamDescriptionProperty, null ; If the desired URL is not the one currently being displayed, the getStream method is called displah give subclasses control over the stream provided.

The base can also be set explicitly in the JEditorPane methods. This requires reading the document prior to determining the character set that is desired. If an IOException is thrown the partially loaded document will be discarded and neither the document or page property change events will be fired.

Images are not scaled correctly in JEditorPane

The setText method can be used to initialize the component from a string. This can be reimplemented to do useful things like fetch the stream from a cache, monitor the progress of the stream, etc. If the type was registered with a ClassLoaderthat ClassLoader will be used to load the prototype.

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. By default, the following types of content are known: String getText Returns the text contained in this TextComponent in terms of the content type of this editor.

And because I haven’t set the size of the window you can set it larger to see image. 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.

If the document is jedtorpane 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. I have a JEditorPane created by this way: