Interface Caret
- All Known Implementing Classes:
-
BasicTextUI.BasicCaret
,DefaultCaret
public interface Caret
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
Modifier and Type | Method | Description |
---|---|---|
void |
addChangeListener |
Adds a listener to track whenever the caret position has been changed. |
void |
deinstall |
Called when the UI is being removed from the interface of a JTextComponent. |
int |
getBlinkRate() |
Gets the blink rate of the caret. |
int |
getDot() |
Fetches the current position of the caret. |
Point |
getMagicCaretPosition() |
Gets the current caret visual location. |
int |
getMark() |
Fetches the current position of the mark. |
void |
install |
Called when the UI is being installed into the interface of a JTextComponent. |
boolean |
isSelectionVisible() |
Determines if the selection is currently visible. |
boolean |
isVisible() |
Determines if the caret is currently visible. |
void |
moveDot |
Moves the caret position (dot) to some other position, leaving behind the mark. |
void |
paint |
Renders the caret. |
void |
removeChangeListener |
Removes a listener that was tracking caret position changes. |
void |
setBlinkRate |
Sets the blink rate of the caret. |
void |
setDot |
Sets the caret position to some position. |
void |
setMagicCaretPosition |
Set the current caret visual location. |
void |
setSelectionVisible |
Sets the visibility of the selection |
void |
setVisible |
Sets the visibility of the caret. |
Method Details
install
void install(JTextComponent c)
- Parameters:
-
c
- the JTextComponent
deinstall
void deinstall(JTextComponent c)
- Parameters:
-
c
- the JTextComponent
paint
void paint(Graphics g)
- Parameters:
-
g
- the graphics context
addChangeListener
void addChangeListener(ChangeListener l)
- Parameters:
-
l
- the change listener
removeChangeListener
void removeChangeListener(ChangeListener l)
- Parameters:
-
l
- the change listener
isVisible
boolean isVisible()
- Returns:
- true if the caret is visible else false
setVisible
void setVisible(boolean v)
- Parameters:
-
v
- true if the caret should be shown, and false if the caret should be hidden
isSelectionVisible
boolean isSelectionVisible()
- Returns:
- true if the caret is visible else false
setSelectionVisible
void setSelectionVisible(boolean v)
- Parameters:
-
v
- true if the caret should be shown, and false if the caret should be hidden
setMagicCaretPosition
void setMagicCaretPosition(Point p)
- Parameters:
-
p
- the Point to use for the saved position. This can be null to indicate there is no visual location.
getMagicCaretPosition
Point getMagicCaretPosition()
- Returns:
- the visual position.
- See Also:
setBlinkRate
void setBlinkRate(int rate)
- Parameters:
-
rate
- the delay in milliseconds >=0. If this is zero the caret will not blink.
getBlinkRate
int getBlinkRate()
- Returns:
- the delay in milliseconds >=0. If this is zero the caret will not blink.
getDot
int getDot()
- Returns:
- the position >=0
getMark
int getMark()
- Returns:
- the position >=0
setDot
void setDot(int dot)
If the parameter is negative or beyond the length of the document, the caret is placed at the beginning or at the end, respectively.
- Parameters:
-
dot
- the new position to set the caret to
moveDot
void moveDot(int dot)
- Parameters:
-
dot
- the new position to move the caret to >=0
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/text/Caret.html