Java Reference
In-Depth Information
JTextPane Class
The JTextPane is a specialized form of the JEditorPane designed especially for the editing (and
display) of styled text. It differs from the JEditorPane only in its manner of providing the content to
display because the text isn't tagged with the styles as it would be in an HTML or RTF document.
The JTextPane relies on three interfaces for the setting of text attributes: AttributeSet for
a basic collection of attributes, MutableAttributeSet for a changeable collection of attributes,
and Style for a set of attributes to be associated with a part of a StyledDocument .
This section will introduce JTextPane . See Chapter 16 for additional information about
configuring styles for different parts of the styled content within a JTextPane .
Creating a JTextPane
There are only two constructors for JTextPane :
public JTextPane()
JTextPane textPane = new JTextPane();
JScrollPane scrollPane = new JScrollPane(textPane);
public JTextPane(StyledDocument document)
StyledDocument document = new DefaultStyledDocument();
JTextPane textPane = new JTextPane(document);
JScrollPane scrollPane = new JScrollPane(textPane);
The no-argument constructor initially has zero contents. The second constructor allows
you to create the Document first, and then use it in the JTextPane .
Tip Remember to place your JTextPane within a JScrollPane if the contents will be larger than the
available screen space.
JTextPane Properties
Table 15-14 shows the eight properties of JTextPane . You'll look at these in greater detail in
Chapter 16.
Table 15-14. JTextPane Properties
Property Name
Data Type
Access
characterAttributes
AttributeSet
Read-only
document
Document
Write-only bound
editorKit
EditorKit
Write-only bound
 
Search WWH ::




Custom Search