我在用poi操作excel时,需要得到字符串的宽度,别人告诉我awt包中有这么样的方法,于是我在程序中是这么写的,但是感觉得到的不准确
Font stringFont = new Font(newFont.getFontName(),Font.PLAIN, 9);
Graphics graphics =new java.awt.image.BufferedImage(10,10
,java.awt.image.BufferedImage.TYPE_INT_ARGB ).getGraphics();
FontMetrics fontMetrics = graphics.getFontMetrics(stringFont);
int stringWidth = fontMetrics.stringWidth(s);
这样得到的stringWidth要比实际的大
难道我的方法有错?
Font stringFont = new Font(newFont.getFontName(),Font.PLAIN, 9);
Graphics graphics =new java.awt.image.BufferedImage(10,10
,java.awt.image.BufferedImage.TYPE_INT_ARGB ).getGraphics();
FontMetrics fontMetrics = graphics.getFontMetrics(stringFont);
int stringWidth = fontMetrics.stringWidth(s);
这样得到的stringWidth要比实际的大
难道我的方法有错?