Text
组件APIThe Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
This section lists commonly used parts of the API that are shared by text components. 本节列出了文本组件共享的API常用部分。Much of this API is defined by the 该API的大部分由JTextComponent
class. JTextComponent
类定义。Text Component Features discusses how to use some of this API.文本组件功能讨论了如何使用一些API。
The JComponent ClassJComponent
类 describes the API that text components inherit from 描述文本组件从JComponent
. JComponent
继承的API。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.有关与特定文本组件相关的API的信息,请参阅该组件的操作指南页:文本字段、密码字段、格式化文本字段、文本区域或编辑器窗格和文本窗格。
For complete details about the text API, see the API documentation for 有关文本API的完整详细信息,请参阅JTextComponent
and for the various classes and interfaces in the text package.JTextComponent
的API文档以及文本包中的各种类和接口。
The API listed in this section includes the following categories:本节列出的API包括以下类别:
void setEditable(boolean) boolean isEditable()
|
|
void setDragEnabled(boolean) boolean getDragEnabled() |
dragEnabled property, which must be true to enable drag handling on this component. dragEnabled 属性,该属性必须为true 才能在此组件上启用拖动处理。false 。 |
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() |
int viewToModel(Point) |
|
Rectangle modelToView(int) |
void cut() void copy() void paste() void replaceSelection(String) (in JTextComponent ) |
|
EditorKit |
|
DefaultEditorKit |
EditorKit that provides the basic text editing capabilities.EditorKit 的一个具体子类,提供基本的文本编辑功能。 |
StyledEditorKit |
Default EditorKit that provides additional editing capabilities for styled text.EditorKit 的子类,为样式化文本提供额外的编辑功能。 |
String xxxxAction (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 ) |
|
InputMap getInputMap() (in JComponent ) |
|
void put(KeyStroke, Object) (in InputMap ) |
DefaultEditorKit.backwardAction .DefaultEditorKit.backwardAction 。 |
Document |
|
AbstractDocument |
Document interface. Document 接口的抽象超类实现。 |
PlainDocument |
Document interface. Document 接口的类。 |
StyledDocument |
Document subinterface. Document 子接口。JTextPane requires that its document be of this type.JTextPane 要求其文档为这种类型。 |
DefaultStyledDocument |
StyledDocument interface. StyledDocument 接口的类。JTextPane .JTextPane 的默认文档。 |
DocumentFilter |
|
void setDocumentFilter(DocumentFilter) (in AbstractDocument ) |
|
void setDocument(Document) Document getDocument() (in JTextComponent ) |
|
Document createDefaultModel() (in JTextField ) |
PlainDocument .PlainDocument 。 |
void addDocumentListener(DocumentListener) void removeDocumentListener(DocumentListener) (in Document ) |
|
void addUndoableEditListener(UndoableEditListener) void removeUndoableEditListener(UndoableEditlistener) (in Document ) |
|
int getLength() Position getStartPosition() Position getEndPosition() String getText(int, int) (in Document ) |
Document methods that return various descriptive information about the document.Document 方法。 |
Object getProperty(Object) void putProperty(Object, Object) (in Document )void setDocumentProperties(Dictionary) Dictionary getDocumentProperties() (in AbstractDocument ) |
Document maintains a set of properties that you can manipulate with these methods.Document 维护一组属性,您可以使用这些方法操作这些属性。 |
Caret |
|
DefaultCaret |
|
void setCaret(Caret) Caret getCaret() |
|
void setCaretColor(Color) Color getCaretColor() |
|
void setCaretPosition(int) void moveCaretPosition(int) int getCaretPosition() |
|
void addCaretListener(CaretListener) void removeCaretListener(CaretListener) |
|
NavigationFilter |
|
void setNavigationFilter(NavigationFilter) |
|
Highlighter |
|
DefaultHighlighter |
|
void setHighlighter(Highlighter) Highlighter getHighlighter() |
void read(Reader, Object) void write(Writer) (in JTextComponent ) |
|
void read(Reader, Document, int) void read(InputStream, Document, int) (in EditorKit ) |
|
void write(Writer, Document, int, int) void write(OutputStream, Document, int, int) (in EditorKit ) |