日期:2014-05-20  浏览次数:20699 次

怎么样获取一个字符串占多少像素?
String   str   =   "abceWWWwww ";

怎样获取一个字符串占了多少像素?

------解决方案--------------------
不懂,一直以為隻有圖像才會有像素呢。
這次增見識了。。
------解决方案--------------------
象素?你说清楚点啊,等宽的和一般的可是不一样的啊
------解决方案--------------------
重写paintComponent方法

Font font = new Font(...);
g2.setFont(font);
String str = "abclLGg ";
Rectangle2D rect = font.getStringBounds(str, g2.getFontRenderContext());
double width = rect.getWidth();

随便写的,有错请讲..