2009-10-05 6 views

Répondre

0
Text text = new Text(parent, SWT.NONE); 
text.setText("This"); 

GC gc = new GC(text); 
int currentPixelsX = text.getBounds().x; 
int currentPixelsY = text.getBounds().y; 
for (int i = 0; i < text.getText().length(); i++) { 
    System.out.println("X co-ordinate of " + text.getText().charAt(i) + ":" + currentPixelsX); 
    System.out.println("Y co-ordinate of " + text.getText().charAt(i) + ":" + currentPixelsY); 

    currentPixelsX = currentPixelsX + gc.getCharWidth(text.getText().charAt(i)); 
} 

Ceci donne les coordonnées des pixels par rapport au parent de la zone de texte.

+0

La solution que vous proposez ne pas accueillir des ajustements d'espacement espacement char/mot de GDI. –

0

Probablement this Snippet peut vous aider à calculer la longueur individuelle d'un caractère

Questions connexes