Home Page
>
Creating a GUI with JFC/Swing
>
Using Swing Components
The Text Component API
This section lists commonly used parts
of the API that are shared by text components.
Much of this API is defined by the
JTextComponent class.
Text Component Features
discusses how to use some of this API.
The JComponent Class
describes the API that text components
inherit from JComponent.
For information about the API
related to specific text components,
see the how-to page for that component:
text field,
password field,
formatted text field,
text area, or
editor pane and text pane.
For complete details about the text API,
see the API documentation for
JTextComponent and for the various classes and
interfaces in the
text package.
The API listed in this section includes the following categories:
Text Editing Commands
| Class or Method | Description
|
void cut()
void copy()
void paste()
void replaceSelection(String) (in JTextComponent)
|
Cuts, copies, and pastes text using the system clipboard,
or replaces the selected text with the string specified by an argument, respectively.
|
|
EditorKit |
Provides a text component's view factory, document, caret, and actions,
as well as reading and writing
documents of a particular format.
|
|
DefaultEditorKit |
A concrete subclass of EditorKit that
provides the basic text editing capabilities.
|
|
StyledEditorKit |
A subclass of Default EditorKit that
provides additional editing capabilities for styled text.
|
String xxxxAction (in DefaultEditorKit)
|
The names of all the actions supported by the default editor kit.
See Associating Text Actions with
Menus and Buttons.
|
BeepAction
CopyAction
CutAction
DefaultKeyTypedAction
InsertBreakAction
InsertContentAction
InsertTabAction
PasteAction (in DefaultEditorKit)
|
Inner classes that implement various text editing commands.
|
AlignmentAction
BoldAction
FontFamilyAction
FontSizeAction
ForegroundAction
ItalicAction
StyledTextAction
UnderlineAction (in StyledEditorKit)
|
Inner classes that implement various editing commands
for styled text.
|
Action[] getActions() (in JTextComponent)
|
Gets the actions supported by this component.
This method gets the array of actions from the editor kit
if one is used by the component.
|
InputMap getInputMap() (in JComponent)
|
Gets the input map that binds key strokes to actions.
See
Associating
Text Actions with Key Strokes.
|
void put(KeyStroke, Object) (in InputMap)
|
Binds the specified key to the specified action.
You generally specify the action by its name,
which for standard editing actions is
represented by a string constant such as
DefaultEditorKit.backwardAction.
|
Classes and Interfaces That Represent Documents
| Interface or Class | Description
|
|
Document |
An interface that defines the API that must be implemented
by all documents.
|
|
AbstractDocument |
An abstract superclass implementation
of the Document interface.
This is the superclass for all documents
provided by the Swing text package.
|
|
PlainDocument |
A class that implements the Document interface.
This is the default document for the plain text components
(text field, password field, and text area).
Additionally, this class is used by the editor panes and text panes
when loading plain text or text of an unknown format.
|
|
StyledDocument |
A Document subinterface.
Defines the API that must be implemented by documents that
support styled text.
JTextPane requires that its document be of this type.
|
|
DefaultStyledDocument |
A class that implements the StyledDocument interface.
The default document for JTextPane.
|
Reading and Writing Text
| Method | Description
|
void read(Reader, Object)
void write(Writer) (in JTextComponent)
|
Reads or writes text.
|
void read(Reader, Document, int)
void read(InputStream, Document, int) (in EditorKit)
|
Reads text from a stream into a document.
|
void write(Writer, Document, int, int)
void write(OutputStream, Document, int, int) (in EditorKit)
|
Writes text from a document to a stream.
|