javax.swing.text
Interface Caret

All Known Implementing Classes:
BasicTextUI.BasicCaret sample code for javax.swing.plaf.basic.BasicTextUI.BasicCaret definition code for javax.swing.plaf.basic.BasicTextUI.BasicCaret , DefaultCaret sample code for javax.swing.text.DefaultCaret definition code for javax.swing.text.DefaultCaret

public interface Caret

A place within a document view that represents where things can be inserted into the document model. A caret has a position in the document referred to as a dot. The dot is where the caret is currently located in the model. There is a second position maintained by the caret that represents the other end of a selection called mark. If there is no selection the dot and mark will be equal. If a selection exists, the two values will be different.

The dot can be placed by either calling setDot or moveDot. Setting the dot has the effect of removing any selection that may have previously existed. The dot and mark will be equal. Moving the dot has the effect of creating a selection as the mark is left at whatever position it previously had.


Method Summary
 void addChangeListener sample code for javax.swing.text.Caret.addChangeListener(javax.swing.event.ChangeListener) definition code for javax.swing.text.Caret.addChangeListener(javax.swing.event.ChangeListener) (ChangeListener sample code for javax.swing.event.ChangeListener definition code for javax.swing.event.ChangeListener  l)
          Adds a listener to track whenever the caret position has been changed.
 void deinstall sample code for javax.swing.text.Caret.deinstall(javax.swing.text.JTextComponent) definition code for javax.swing.text.Caret.deinstall(javax.swing.text.JTextComponent) (JTextComponent sample code for javax.swing.text.JTextComponent definition code for javax.swing.text.JTextComponent  c)
          Called when the UI is being removed from the interface of a JTextComponent.
 int getBlinkRate sample code for javax.swing.text.Caret.getBlinkRate() definition code for javax.swing.text.Caret.getBlinkRate() ()
          Gets the blink rate of the caret.
 int getDot sample code for javax.swing.text.Caret.getDot() definition code for javax.swing.text.Caret.getDot() ()
          Fetches the current position of the caret.
 Point sample code for java.awt.Point definition code for java.awt.Point getMagicCaretPosition sample code for javax.swing.text.Caret.getMagicCaretPosition() definition code for javax.swing.text.Caret.getMagicCaretPosition() ()
          Gets the current caret visual location.
 int getMark sample code for javax.swing.text.Caret.getMark() definition code for javax.swing.text.Caret.getMark() ()
          Fetches the current position of the mark.
 void install sample code for javax.swing.text.Caret.install(javax.swing.text.JTextComponent) definition code for javax.swing.text.Caret.install(javax.swing.text.JTextComponent) (JTextComponent sample code for javax.swing.text.JTextComponent definition code for javax.swing.text.JTextComponent  c)
          Called when the UI is being installed into the interface of a JTextComponent.
 boolean isSelectionVisible sample code for javax.swing.text.Caret.isSelectionVisible() definition code for javax.swing.text.Caret.isSelectionVisible() ()
          Determines if the selection is currently visible.
 boolean isVisible sample code for javax.swing.text.Caret.isVisible() definition code for javax.swing.text.Caret.isVisible() ()
          Determines if the caret is currently visible.
 void moveDot sample code for javax.swing.text.Caret.moveDot(int) definition code for javax.swing.text.Caret.moveDot(int) (int dot)
          Moves the caret position (dot) to some other position, leaving behind the mark.
 void paint sample code for javax.swing.text.Caret.paint(java.awt.Graphics) definition code for javax.swing.text.Caret.paint(java.awt.Graphics) (Graphics sample code for java.awt.Graphics definition code for java.awt.Graphics  g)
          Renders the caret.
 void removeChangeListener sample code for javax.swing.text.Caret.removeChangeListener(javax.swing.event.ChangeListener) definition code for javax.swing.text.Caret.removeChangeListener(javax.swing.event.ChangeListener) (ChangeListener sample code for javax.swing.event.ChangeListener definition code for javax.swing.event.ChangeListener  l)
          Removes a listener that was tracking caret position changes.
 void setBlinkRate sample code for javax.swing.text.Caret.setBlinkRate(int) definition code for javax.swing.text.Caret.setBlinkRate(int) (int rate)
          Sets the blink rate of the caret.
 void setDot sample code for javax.swing.text.Caret.setDot(int) definition code for javax.swing.text.Caret.setDot(int) (int dot)
          Sets the caret position to some position.
 void setMagicCaretPosition sample code for javax.swing.text.Caret.setMagicCaretPosition(java.awt.Point) definition code for javax.swing.text.Caret.setMagicCaretPosition(java.awt.Point) (Point sample code for java.awt.Point definition code for java.awt.Point  p)
          Set the current caret visual location.
 void setSelectionVisible sample code for javax.swing.text.Caret.setSelectionVisible(boolean) definition code for javax.swing.text.Caret.setSelectionVisible(boolean) (boolean v)
          Sets the visibility of the selection
 void setVisible sample code for javax.swing.text.Caret.setVisible(boolean) definition code for javax.swing.text.Caret.setVisible(boolean) (boolean v)
          Sets the visibility of the caret.
 

Method Detail

install sample code for javax.swing.text.Caret.install(javax.swing.text.JTextComponent) definition code for javax.swing.text.Caret.install(javax.swing.text.JTextComponent)

void install(JTextComponent sample code for javax.swing.text.JTextComponent definition code for javax.swing.text.JTextComponent  c)
Called when the UI is being installed into the interface of a JTextComponent. This can be used to gain access to the model that is being navigated by the implementation of this interface.

Parameters:
c - the JTextComponent

deinstall sample code for javax.swing.text.Caret.deinstall(javax.swing.text.JTextComponent) definition code for javax.swing.text.Caret.deinstall(javax.swing.text.JTextComponent)

void deinstall(JTextComponent sample code for javax.swing.text.JTextComponent definition code for javax.swing.text.JTextComponent  c)
Called when the UI is being removed from the interface of a JTextComponent. This is used to unregister any listeners that were attached.

Parameters:
c - the JTextComponent

paint sample code for javax.swing.text.Caret.paint(java.awt.Graphics) definition code for javax.swing.text.Caret.paint(java.awt.Graphics)

void paint(Graphics sample code for java.awt.Graphics definition code for java.awt.Graphics  g)
Renders the caret.

Parameters:
g - the graphics context

addChangeListener sample code for javax.swing.text.Caret.addChangeListener(javax.swing.event.ChangeListener) definition code for javax.swing.text.Caret.addChangeListener(javax.swing.event.ChangeListener)

void addChangeListener(ChangeListener sample code for javax.swing.event.ChangeListener definition code for javax.swing.event.ChangeListener  l)
Adds a listener to track whenever the caret position has been changed.

Parameters:
l - the change listener

removeChangeListener sample code for javax.swing.text.Caret.removeChangeListener(javax.swing.event.ChangeListener) definition code for javax.swing.text.Caret.removeChangeListener(javax.swing.event.ChangeListener)

void removeChangeListener(ChangeListener sample code for javax.swing.event.ChangeListener definition code for javax.swing.event.ChangeListener  l)
Removes a listener that was tracking caret position changes.

Parameters:
l - the change listener

isVisible sample code for javax.swing.text.Caret.isVisible() definition code for javax.swing.text.Caret.isVisible()

boolean isVisible()
Determines if the caret is currently visible.

Returns:
true if the caret is visible else false

setVisible sample code for javax.swing.text.Caret.setVisible(boolean) definition code for javax.swing.text.Caret.setVisible(boolean)

void setVisible(boolean v)
Sets the visibility of the caret.

Parameters:
v - true if the caret should be shown, and false if the caret should be hidden

isSelectionVisible sample code for javax.swing.text.Caret.isSelectionVisible() definition code for javax.swing.text.Caret.isSelectionVisible()

boolean isSelectionVisible()
Determines if the selection is currently visible.

Returns:
true if the caret is visible else false

setSelectionVisible sample code for javax.swing.text.Caret.setSelectionVisible(boolean) definition code for javax.swing.text.Caret.setSelectionVisible(boolean)

void setSelectionVisible(boolean v)
Sets the visibility of the selection

Parameters:
v - true if the caret should be shown, and false if the caret should be hidden

setMagicCaretPosition sample code for javax.swing.text.Caret.setMagicCaretPosition(java.awt.Point) definition code for javax.swing.text.Caret.setMagicCaretPosition(java.awt.Point)

void setMagicCaretPosition(Point sample code for java.awt.Point definition code for java.awt.Point  p)
Set the current caret visual location. This can be used when moving between lines that have uneven end positions (such as when caret up or down actions occur). If text flows left-to-right or right-to-left the x-coordinate will indicate the desired navigation location for vertical movement. If the text flow is top-to-bottom, the y-coordinate will indicate the desired navigation location for horizontal movement.

Parameters:
p - the Point to use for the saved position. This can be null to indicate there is no visual location.

getMagicCaretPosition sample code for javax.swing.text.Caret.getMagicCaretPosition() definition code for javax.swing.text.Caret.getMagicCaretPosition()

Point sample code for java.awt.Point definition code for java.awt.Point  getMagicCaretPosition()
Gets the current caret visual location.

Returns:
the visual position.
See Also:
setMagicCaretPosition(java.awt.Point) sample code for javax.swing.text.Caret.setMagicCaretPosition(java.awt.Point) definition code for javax.swing.text.Caret.setMagicCaretPosition(java.awt.Point)

setBlinkRate sample code for javax.swing.text.Caret.setBlinkRate(int) definition code for javax.swing.text.Caret.setBlinkRate(int)

void setBlinkRate(int rate)
Sets the blink rate of the caret. This determines if and how fast the caret blinks, commonly used as one way to attract attention to the caret.

Parameters:
rate - the delay in milliseconds >= 0. If this is zero the caret will not blink.

getBlinkRate sample code for javax.swing.text.Caret.getBlinkRate() definition code for javax.swing.text.Caret.getBlinkRate()

int getBlinkRate()
Gets the blink rate of the caret. This determines if and how fast the caret blinks, commonly used as one way to attract attention to the caret.

Returns:
the delay in milliseconds >= 0. If this is zero the caret will not blink.

getDot sample code for javax.swing.text.Caret.getDot() definition code for javax.swing.text.Caret.getDot()

int getDot()
Fetches the current position of the caret.

Returns:
the position >= 0

getMark sample code for javax.swing.text.Caret.getMark() definition code for javax.swing.text.Caret.getMark()

int getMark()
Fetches the current position of the mark. If there is a selection, the mark will not be the same as the dot.

Returns:
the position >= 0

setDot sample code for javax.swing.text.Caret.setDot(int) definition code for javax.swing.text.Caret.setDot(int)

void setDot(int dot)
Sets the caret position to some position. This causes the mark to become the same as the dot, effectively setting the selection range to zero.

Parameters:
dot - the new position to set the caret to >= 0

moveDot sample code for javax.swing.text.Caret.moveDot(int) definition code for javax.swing.text.Caret.moveDot(int)

void moveDot(int dot)
Moves the caret position (dot) to some other position, leaving behind the mark. This is useful for making selections.

Parameters:
dot - the new position to move the caret to >= 0