public final class TextHitInfo extends Object
TextHitInfo class represents a character position in a text model, and a bias, or "side," of the character. Biases are either leading (the left edge, for a left-to-right character) or trailing (the right edge, for a left-to-right character). Instances of TextHitInfo are used to specify caret and insertion positions within text. For example, consider the text "abc". TextHitInfo.trailing(1) corresponds to the right side of the 'b' in the text.
 TextHitInfo is used primarily by TextLayout and clients of TextLayout. Clients of TextLayout query TextHitInfo instances for an insertion offset, where new text is inserted into the text model. The insertion offset is equal to the character position in the TextHitInfo if the bias is leading, and one character after if the bias is trailing. The insertion offset for TextHitInfo.trailing(1) is 2. 
 Sometimes it is convenient to construct a TextHitInfo with the same insertion offset as an existing one, but on the opposite character. The getOtherHit method constructs a new TextHitInfo with the same insertion offset as an existing one, with a hit on the character on the other side of the insertion offset. Calling getOtherHit on trailing(1) would return leading(2). In general, getOtherHit for trailing(n) returns leading(n+1) and getOtherHit for leading(n) returns trailing(n-1). 
Example:
Converting a graphical point to an insertion point within a text model
TextLayout layout = ...; Point2D.Float hitPoint = ...; TextHitInfo hitInfo = layout.hitTestChar(hitPoint.x, hitPoint.y); int insPoint = hitInfo.getInsertionIndex(); // insPoint is relative to layout; may need to adjust for use // in a text model
| Modifier and Type | Method | Description | 
|---|---|---|
| static TextHitInfo | afterOffset | Creates a  TextHitInfoat the specified offset, associated with the character after the offset. | 
| static TextHitInfo | beforeOffset | Creates a  TextHitInfoat the specified offset, associated with the character before the offset. | 
| boolean | equals | Returns  trueif the specifiedTextHitInfohas the samecharIndexandisLeadingEdgeas thisTextHitInfo. | 
| boolean | equals | Returns  trueif the specifiedObjectis aTextHitInfoand equals thisTextHitInfo. | 
| int | getCharIndex() | Returns the index of the character hit. | 
| int | getInsertionIndex() | Returns the insertion index. | 
| TextHitInfo | getOffsetHit | Creates a  TextHitInfowhose character index is offset bydeltafrom thecharIndexof thisTextHitInfo. | 
| TextHitInfo | getOtherHit() | Creates a  TextHitInfoon the other side of the insertion point. | 
| int | hashCode() | Returns the hash code. | 
| boolean | isLeadingEdge() | Returns  trueif the leading edge of the character was hit. | 
| static TextHitInfo | leading | Creates a  TextHitInfoon the leading edge of the character at the specifiedcharIndex. | 
| String | toString() | Returns a  Stringrepresenting the hit for debugging use only. | 
| static TextHitInfo | trailing | Creates a hit on the trailing edge of the character at the specified  charIndex. | 
public int getCharIndex()
public boolean isLeadingEdge()
true if the leading edge of the character was hit.true if the leading edge of the character was hit; false otherwise.public int getInsertionIndex()
public int hashCode()
public boolean equals(Object obj)
true if the specified Object is a TextHitInfo and equals this TextHitInfo.public boolean equals(TextHitInfo hitInfo)
true if the specified TextHitInfo has the same charIndex and isLeadingEdge as this TextHitInfo. This is not the same as having the same insertion offset.hitInfo - a specified TextHitInfo
true if the specified TextHitInfo has the same charIndex and isLeadingEdge as this TextHitInfo.public String toString()
String representing the hit for debugging use only.public static TextHitInfo leading(int charIndex)
TextHitInfo on the leading edge of the character at the specified charIndex.charIndex - the index of the character hitTextHitInfo on the leading edge of the character at the specified charIndex.public static TextHitInfo trailing(int charIndex)
charIndex.charIndex - the index of the character hitTextHitInfo on the trailing edge of the character at the specified charIndex.public static TextHitInfo beforeOffset(int offset)
TextHitInfo at the specified offset, associated with the character before the offset.offset - an offset associated with the character before the offsetTextHitInfo at the specified offset.public static TextHitInfo afterOffset(int offset)
TextHitInfo at the specified offset, associated with the character after the offset.offset - an offset associated with the character after the offsetTextHitInfo at the specified offset.public TextHitInfo getOtherHit()
TextHitInfo on the other side of the insertion point. This TextHitInfo remains unchanged.TextHitInfo on the other side of the insertion point.public TextHitInfo getOffsetHit(int delta)
TextHitInfo whose character index is offset by delta from the charIndex of this TextHitInfo. This TextHitInfo remains unchanged.delta - the value to offset this charIndex
TextHitInfo whose charIndex is offset by delta from the charIndex of this TextHitInfo.
    © 1993, 2023, 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/21/docs/api/java.desktop/java/awt/font/TextHitInfo.html