JScrollPane; import ane; import MutableAttributeSet; import AttributeSet; import javax. JTextPane; //from w w w. j a v a 2 s. c o m public class Main { public static void main(String args[]) { JFrame f = new JFrame(); aultCloseOperation( JFrame. JTextPane is a subclass of JEditorPane class. JTextPane is used for styled document with embedded images and components. It is text component that can be.

Author: Felrajas Samugul
Country: Martinique
Language: English (Spanish)
Genre: Travel
Published (Last): 12 June 2015
Pages: 120
PDF File Size: 13.61 Mb
ePub File Size: 2.46 Mb
ISBN: 335-5-38061-886-8
Downloads: 17453
Price: Free* [*Free Regsitration Required]
Uploader: Kajisar

Examples and practices described in this page don’t take advantage of improvements introduced in later releases. Two Swing classes support styled text: 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.

If you want unstyled text, use a text area instead. You can see jtextpahe editor pane and a text pane in use by running TextSamplerDemo. Here is a picture of the TextSamplerDemo example.

Alternatively, to compile and run the example yourself, consult the example index. The TextSamplerDemo example barely begins to demonstrate the capabilities of editor panes and text panes.

JTextPane To Pdf : to PDF « PDF « Java Tutorial

However, the top right editor pane illustrates a handy, easy-to-use feature: The text pane at the lower right demonstrates that you can easily embed images and even components directly into text panes. If you need a fully-fledged help system, take a look at the javahelp project. The Swing text API is powerful and immense, and we could devote an entire book just to using editor panes and text panes. This section introduces their capabilities, offers hints on which one you might want to use, and points to other sources of information.


One task that you can accomplish without knowing anything about the Swing text system is displaying text jtextpxne a URL. Here is the code from TextSamplerDemo. The code uses the default constructor to create the editor pane, then calls setEditable false so the user cannot edit the text. Next, the code creates the URL object, and calls the setPage method with it. If the jtextpanr format is known, the editor pane initializes itself with the text found at the URL.

JTextPane (Java Platform SE 7 )

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

In order to use editor panes and text panes, you need to understand the text system, which is described in Text Component Features. Several facts about editor panes and text panes jtrxtpane scattered throughout that section. Here we list the facts again and provide a bit more detail.

The information here should help you understand the differences between editor panes and text panes, and when to use which. Be aware that the document and editor kit might change when using the setPage method. 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.


Here is the code from the TextSamplerDemo example that creates and initializes a text pane. Next, the code loops over the arrays, inserts the text into the text pane, and specifies the style to use for the inserted text.

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. Instead, a program would use an editor pane to save a document which would then be used to initialize the text pane.

This section lists some of the API related to text and editor panes. 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.

How to Use Editor Panes and Text Panes

Using Swing Components Section: How to Use Various Jtextpaje. How to Make Dialogs Next page: How to Use File Choosers. Provides a customized text pane. 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.