- 设置属性
- 操纵选择
- 转换模型和视图之间的位置
- 文本编辑命令
- 用来表示文档的类与接口
- 使用Document
- 管理光标与选择高亮
- 读取和写入文本
设置属性
方法 | 描述 |
void setEditable(boolean) boolean isEditable() | 设置或获取用户是否可以编辑文本组件中的文本。 |
void setDragEnabled(boolean) boolean getDragEnabled() | 设置或获取dragEnabled属性,它必须为true才能在此组件上启用拖动处理。 |
void setDisabledTextColor(Color) Color getDisabledTextColor() | 设置或获取用于文本组件被禁用,以显示文本的颜色。 |
void setMargin(Insets) Insets getMargin() | 设置或获取文本和文本组件的边框之间的空白。 |
操作选择
方法 | 描述 |
String getSelectedText() | 获取当前选定的文本。 |
void selectAll() void select(int, int) | 选择一个开始和结束的范围之内的文本。 |
void setSelectionStart(int) void setSelectionEnd(int) int getSelectionStart() int getSelectionEnd() | 设置或获取当前所选的索引位置。 |
void setSelectedTextColor(Color) Color getSelectedTextColor() | 设置或获取所选文本的颜色。 |
void setSelectionColor(Color) Color getSelectionColor() | 设置或获取所选文本的背景色。 |
文本编辑命令
类或方法 | 描述 |
void cut() void copy() void paste() void replaceSelection(String) | 剪切,复制和粘贴文本使用系统剪贴板,或替换选定的文本为参数指定的字符串。 |
EditorKit | 提供了一个文本组件的视图工厂,文档,插入符,和行动,以及特定格式的读取和写入文件。 |
DefaultEditorKit | EditorKit的具体子类,它提供了基本的文本编辑功能。 |
StyledEditorKit | DefaultEditorKit的一个子类,它提供了添加和编辑styled文本的功能。 |
StringxxxxAction (in DefaultEditorKit) | 所有的默认编辑器工具包支持的动作的名称。 |
BeepAction CopyAction CutAction DefaultKeyTypedAction InsertBreakAction InsertContentAction InsertTabAction PasteAction (in DefaultEditorKit) | 实现各种文本编辑命令的内部类。 |
AlignmentAction BoldAction FontFamilyAction FontSizeAction ForegroundAction ItalicAction StyledTextAction UnderlineAction (in StyledEditorKit) | 实现对样式文本的各种编辑命令的内部类。 |
Action[] getActions() (in JTextComponent) | 获取此组件所支持的Actions。这种方法得到的从编辑器工具包的动作的阵列。 |
InputMap getInputMap() (in JComponent) | 获取击键输入绑定的Map。SeeAssociating Text Actions with Key Strokes. |
void put(KeyStroke, Object) (in InputMap) | 绑定指定的键到指定的动作。你通常用它的名字,这对于标准的编辑操作是由一个字符串常量,例如DefaultEditorKit.backwardAction代表指定的操作。 |
用来表示文档的类与接口
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. |
管理光标与选择高亮
nterface, Class, or Method | Description |
Caret | An interface that defines the API for objects that represent an insertion point within documents. |
DefaultCaret | The default caret used by all text components. |
void setCaret(Caret) Caret getCaret() | Sets or gets the caret object used by a text component. |
void setCaretColor(Color) Color getCaretColor() | Sets or gets the color of the caret. |
void setCaretPosition(int) void moveCaretPosition(int) int getCaretPosition() | Sets or gets the current position of the caret within the document. |
void addCaretListener(CaretListener) void removeCaretListener(CaretListener) | Adds or removes a caret listener from a text component. |
NavigationFilter | The superclass for all navigation filters. A navigation filter lets you modify caret changes that are about to occur for a text component. |
void setNavigationFilter(NavigationFilter) | Attaches a navigation filter to a text component. |
Highlighter | An interface that defines the API for objects used to highlight the current selection. |
DefaultHighlighter | The default highlighter used by all text components. |
void setHighlighter(Highlighter) Highlighter getHighlighter() | Sets or gets the highlighter used by a text component. |
读写文本
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. |