Java: Text
If you work with text, you need to know about the following user interface text components.
Component | Lines | Style | Use |
---|---|---|---|
JLabel |
1 plain, HTML "page", and/or an icon | plain or HTML | For displaying a fixed line of text. Can be HTML |
JTextField |
1 | plain | For entering or displaying one line of plain text. |
JFormattedTextField |
1 | plain | Added in SDK 1.4, JFormattedTextField is a subclass of JTextField for which the type of entry may be specified. For example, a field can be constructed to only accept integer values. |
JPasswordField |
1 | plain | For entering one line of plain text that displays a symbol instead of the characters, ie, for entering passwords. Subclass of JTextField. |
JTextArea |
many | plain | For entering or displaying multiple lines of plain text. Put it into a JScrollPane to add scrolling. |
Advanced text components
For display of formatted documents, you might use
JEditorPane
(for displaying plain, HTML, or RTF text)
or JTextPane
, which extends JEditorPane to
allow embedded images and components.
Additional Text features
- Font.
- Text graphics (The Graphics drawString method).
- Summary - Strings.
- Newline Characters.