📄 defaultcaret.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc on Thu Apr 27 23:42:02 PDT 2000 --><TITLE>Java 2 Platform SE v1.3: Class DefaultCaret</TITLE><LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style"></HEAD><BODY BGCOLOR="white"><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_top"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3"> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/DefaultCaret.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>Java<sup><font size=-2>TM</font></sup> 2 Platform<br>Std. Ed. v1.3</b></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../../javax/swing/text/CompositeView.html"><B>PREV CLASS</B></A> <A HREF="../../../javax/swing/text/DefaultEditorKit.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../../index.html" TARGET="_top"><B>FRAMES</B></A> <A HREF="DefaultCaret.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: <A HREF="#inner_classes_inherited_from_class_java.awt.geom.Rectangle2D">INNER</A> | <A HREF="#field_summary">FIELD</A> | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: <A HREF="#field_detail">FIELD</A> | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">javax.swing.text</FONT><BR>Class DefaultCaret</H2><PRE><A HREF="../../../java/lang/Object.html">java.lang.Object</A> | +--<A HREF="../../../java/awt/geom/RectangularShape.html">java.awt.geom.RectangularShape</A> | +--<A HREF="../../../java/awt/geom/Rectangle2D.html">java.awt.geom.Rectangle2D</A> | +--<A HREF="../../../java/awt/Rectangle.html">java.awt.Rectangle</A> | +--<B>javax.swing.text.DefaultCaret</B></PRE><DL><DT><B>All Implemented Interfaces:</B> <DD><A HREF="../../../javax/swing/text/Caret.html">Caret</A>, <A HREF="../../../java/lang/Cloneable.html">Cloneable</A>, <A HREF="../../../java/util/EventListener.html">EventListener</A>, <A HREF="../../../java/awt/event/FocusListener.html">FocusListener</A>, <A HREF="../../../java/awt/event/MouseListener.html">MouseListener</A>, <A HREF="../../../java/awt/event/MouseMotionListener.html">MouseMotionListener</A>, <A HREF="../../../java/io/Serializable.html">Serializable</A>, <A HREF="../../../java/awt/Shape.html">Shape</A></DD></DL><DL><DT><B>Direct Known Subclasses:</B> <DD><A HREF="../../../javax/swing/plaf/basic/BasicTextUI.BasicCaret.html">BasicTextUI.BasicCaret</A></DD></DL><HR><DL><DT>public class <B>DefaultCaret</B><DT>extends <A HREF="../../../java/awt/Rectangle.html">Rectangle</A><DT>implements <A HREF="../../../javax/swing/text/Caret.html">Caret</A>, <A HREF="../../../java/awt/event/FocusListener.html">FocusListener</A>, <A HREF="../../../java/awt/event/MouseListener.html">MouseListener</A>, <A HREF="../../../java/awt/event/MouseMotionListener.html">MouseMotionListener</A></DL><P>A default implementation of Caret. The caret is rendered as a vertical line in the color specified by the CaretColor property of the associated JTextComponent. It can blink at the rate specified by the BlinkRate property. <p> This implementation expects two sources of asynchronous notification. The timer thread fires asynchronously, and causes the caret to simply repaint the most recent bounding box. The caret also tracks change as the document is modified. Typically this will happen on the event thread as a result of some mouse or keyboard event. Updates can also occur from some other thread mutating the document. There is a property <code>AsynchronousMovement</code> that determines if the caret will move on asynchronous updates. The default behavior is to <em>not</em> update on asynchronous updates. If asynchronous updates are allowed, the update thread will fire the caret position change to listeners asynchronously. The repaint of the new caret location will occur on the event thread in any case, as calls to <code>modelToView</code> are only safe on the event thread. <p> The caret acts as a mouse and focus listener on the text component it has been installed in, and defines the caret semantics based upon those events. The listener methods can be reimplemented to change the semantics. By default, the first mouse button will be used to set focus and caret position. Dragging the mouse pointer with the first mouse button will sweep out a selection that is contiguous in the model. If the associated text component is editable, the caret will become visible when focus is gained, and invisible when focus is lost. <p> The Highlighter bound to the associated text component is used to render the selection by default. Selection appearance can be customized by supplying a painter to use for the highlights. By default a painter is used that will render a solid color as specified in the associated text component in the <code>SelectionColor</code> property. This can easily be changed by reimplementing the <a href="#getSelectionHighlighter">getSelectionHighlighter</a> method. <p> A customized caret appearance can be achieved by reimplementing the paint method. If the paint method is changed, the damage method should also be reimplemented to cause a repaint for the area needed to render the caret. The caret extends the Rectangle class which is used to hold the bounding box for where the caret was last rendered. This enables the caret to repaint in a thread-safe manner when the caret moves without making a call to modelToView which is unstable between model updates and view repair (i.e. the order of delivery to DocumentListeners is not guaranteed). <p> The magic caret position is set to null when the caret position changes. A timer is used to determine the new location (after the caret change). When the timer fires, if the magic caret position is still null it is reset to the current caret position. Any actions that change the caret position and want the magic caret position to remain the same, must remember the magic caret position, change the cursor, and then set the magic caret position to its original value. This has the benefit that only actions that want the magic caret position to persist (such as open/down) need to know about it. <p> <strong>Warning:</strong> Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. A future release of Swing will provide support for long term persistence.<P><DL><DT><B>See Also: </B><DD><A HREF="../../../javax/swing/text/Caret.html"><CODE>Caret</CODE></A>, <A HREF="../../../serialized-form.html#javax.swing.text.DefaultCaret">Serialized Form</A></DL><HR><P><!-- ======== INNER CLASS SUMMARY ======== --><A NAME="inner_classes_inherited_from_class_java.awt.geom.Rectangle2D"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Inner classes inherited from class java.awt.geom.<A HREF="../../../java/awt/geom/Rectangle2D.html">Rectangle2D</A></B></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><A HREF="../../../java/awt/geom/Rectangle2D.Double.html">Rectangle2D.Double</A>, <A HREF="../../../java/awt/geom/Rectangle2D.Float.html">Rectangle2D.Float</A></CODE></TD></TR></TABLE> <!-- =========== FIELD SUMMARY =========== --><A NAME="field_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Field Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected <A HREF="../../../javax/swing/event/ChangeEvent.html">ChangeEvent</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../../javax/swing/text/DefaultCaret.html#changeEvent">changeEvent</A></B></CODE><BR> The change event for the model.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected <A HREF="../../../javax/swing/event/EventListenerList.html">EventListenerList</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../../javax/swing/text/DefaultCaret.html#listenerList">listenerList</A></B></CODE><BR> The event listener list.</TD></TR></TABLE> <A NAME="fields_inherited_from_class_java.awt.Rectangle"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Fields inherited from class java.awt.<A HREF="../../../java/awt/Rectangle.html">Rectangle</A></B></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><A HREF="../../../java/awt/Rectangle.html#height">height</A>, <A HREF="../../../java/awt/Rectangle.html#width">width</A>, <A HREF="../../../java/awt/Rectangle.html#x">x</A>, <A HREF="../../../java/awt/Rectangle.html#y">y</A></CODE></TD></TR></TABLE> <A NAME="fields_inherited_from_class_java.awt.geom.Rectangle2D"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Fields inherited from class java.awt.geom.<A HREF="../../../java/awt/geom/Rectangle2D.html">Rectangle2D</A></B></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><A HREF="../../../java/awt/geom/Rectangle2D.html#OUT_BOTTOM">OUT_BOTTOM</A>, <A HREF="../../../java/awt/geom/Rectangle2D.html#OUT_LEFT">OUT_LEFT</A>, <A HREF="../../../java/awt/geom/Rectangle2D.html#OUT_RIGHT">OUT_RIGHT</A>, <A HREF="../../../java/awt/geom/Rectangle2D.html#OUT_TOP">OUT_TOP</A></CODE></TD></TR></TABLE> <!-- ======== CONSTRUCTOR SUMMARY ======== --><A NAME="constructor_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Constructor Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../../javax/swing/text/DefaultCaret.html#DefaultCaret()">DefaultCaret</A></B>()</CODE><BR> Constructs a default caret.</TD></TR></TABLE> <!-- ========== METHOD SUMMARY =========== --><A NAME="method_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Method Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../../javax/swing/text/DefaultCaret.html#addChangeListener(javax.swing.event.ChangeListener)">addChangeListener</A></B>(<A HREF="../../../javax/swing/event/ChangeListener.html">ChangeListener</A> l)</CODE><BR> Adds a listener to track whenever the caret position has been changed.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected void</CODE></FONT></TD>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -