|
Java Example Program/ Sample Source Code
import java.awt.Component;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.font.FontRenderContext;
import java.awt.font.TextHitInfo;
import java.awt.font.TextLayout;
public class GetInsertionIndex_TextHitInfo {
public static void main(String[] args) {
Frame frame = new Frame("GetInsertionIndex_TextHitInfo");
frame.setSize(500, 150);
frame.add(new CanvasToDisplay());
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
class CanvasToDisplay extends Component {
private TextLayout textLayout;
private int x = 40, y = 80;
public CanvasToDisplay() {
addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent me) {
TextHitInfo hitInfo = textLayout.hitTestChar(me.getX() - x, me.getY() - y);
System.out.println("getCharIndex " + hitInfo.getCharIndex());
System.out.println("getInsertionIndex " + hitInfo.getInsertionIndex());
System.out.println("isLeadingEdge " + hitInfo.isLeadingEdge());
}
});
}
public void paint(Graphics g) {
Graphics2D g2D = (Graphics2D) g;
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Font plainFont = new Font("Serif", Font.PLAIN, 82);
g2D.setFont(plainFont);
if (textLayout == null) {
FontRenderContext fontRenderContext = g2D.getFontRenderContext();
textLayout = new TextLayout("JavaTips.net", plainFont, fontRenderContext);
}
textLayout.draw(g2D, x, y);
}
} |
|
|
GlyphVector
- How To Use GlyphVector
- getFont() In GlyphVector
- getFontRenderContext() In GlyphVector
- getGlyphCharIndex(int glyphIndex) In GlyphVector
- getGlyphCharIndices(int beginGlyphIndex, int numEntries, int[] codeReturn) In GlyphVector
- getGlyphCode(int glyphIndex) In GlyphVector
- getGlyphCodes(int beginGlyphIndex, int numEntries, int[] codeReturn) In GlyphVector
- getGlyphJustificationInfo(int glyphIndex) In GlyphVector
- getGlyphLogicalBounds(int glyphIndex) In GlyphVector
- getGlyphMetrics(int glyphIndex) In GlyphVector
- getGlyphOutline(int glyphIndex) In GlyphVector
- getGlyphOutline(int glyphIndex, float x, float y) In GlyphVector
- getGlyphPixelBounds(int index, FontRenderContext renderFRC, float x, float y) In GlyphVector
- getGlyphPosition(int glyphIndex) In GlyphVector
- getGlyphPositions(int beginGlyphIndex, int numEntries, float[] positionReturn) In GlyphVector
- getGlyphTransform(int glyphIndex) In GlyphVector
- getGlyphVisualBounds(int glyphIndex) In GlyphVector
- getLayoutFlags() In GlyphVector
- getLogicalBounds() In GlyphVector
- getNumGlyphs() In GlyphVector
- getOutline() In GlyphVector
- getOutline(float x, float y) In GlyphVector
- getPixelBounds(FontRenderContext renderFRC, float x, float y) In GlyphVector
- getVisualBounds() In GlyphVector
- performDefaultLayout() In GlyphVector
- setGlyphPosition(int glyphIndex, Point2D newPos) In GlyphVector
- setGlyphTransform(int glyphIndex, AffineTransform newTX) In GlyphVector
TextLayout
- How To Use TextLayout
- Getting The Shape From The Outline Of Text
- draw(Graphics2D g2, float x, float y) In TextLayout
- getAdvance() In TextLayout
- getAscent() In TextLayout
- getBaseline() In TextLayout
- getBaselineOffsets() In TextLayout
- getBlackBoxBounds(int firstEndpoint, int secondEndpoint) In TextLayout
- getBounds() In TextLayout
- getCaretInfo(TextHitInfo hit) In TextLayout
- getCaretInfo(TextHitInfo hit, Rectangle2D bounds) In TextLayout
- getCaretShape(TextHitInfo hit) In TextLayout
- getCaretShape(TextHitInfo hit, Rectangle2D bounds) In TextLayout
- getCaretShapes(int offset) In TextLayout
- getCaretShapes(int offset, Rectangle2D bounds) In TextLayout
- getCaretShapes(int offset, Rectangle2D bounds, TextLayout.CaretPolicy policy) In TextLayout
- getCharacterCount() In TextLayout
- getCharacterLevel(int index) In TextLayout
- getDescent() In TextLayout
- getJustifiedLayout(float justificationWidth) In TextLayout
- getLayoutPath() In TextLayout
- getLeading() In TextLayout
- getLogicalHighlightShape(int firstEndpoint, int secondEndpoint) In TextLayout
- getLogicalHighlightShape(int firstEndpoint, int secondEndpoint, Rectangle2D bounds) In TextLayout
- getLogicalRangesForVisualSelection(TextHitInfo firstEndpoint, TextHitInfo secondEndpoint) In TextLayout
- getNextLeftHit(int offset) In TextLayout
- getNextLeftHit(int offset, TextLayout.CaretPolicy policy) In TextLayout
- getNextLeftHit(TextHitInfo hit) In TextLayout
- getNextRightHit(int offset) In TextLayout
- getNextRightHit(int offset, TextLayout.CaretPolicy policy) In TextLayout
- getNextRightHit(TextHitInfo hit) In TextLayout
- getOutline(AffineTransform tx) In TextLayout
- getPixelBounds(FontRenderContext frc, float x, float y) In TextLayout
- getVisibleAdvance() In TextLayout
- getVisualHighlightShape(TextHitInfo firstEndpoint, TextHitInfo secondEndpoint) In TextLayout
- getVisualHighlightShape(TextHitInfo firstEndpoint, TextHitInfo secondEndpoint, Rectangle2D bounds) In TextLayout
- getVisualOtherHit(TextHitInfo hit) In TextLayout
- handleJustify(float justificationWidth) In TextLayout
- hitTestChar(float x, float y) In TextLayout
- hitTestChar(float x, float y, Rectangle2D bounds) In TextLayout
- hitToPoint(TextHitInfo hit, Point2D point) In TextLayout
- isLeftToRight() In TextLayout
- isVertical() In TextLayout
|
|
|
|
|