2009-10-05 39 views

回答

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)); 
} 

這給出了相對於文本框的父親的像素座標。

+0

你的建議無法容納的GDI的字符間距/字間距調整該解決方案的各個長度。 – 2009-10-11 15:54:03

0

大概this片段可以幫你計算字符