
首先,您可以使用TextLayout类及其关联的内容来测量您的Strings
。例如
public static void main(final String[] args) throws Exception{ final FontRenderContext frc = new FontRenderContext(null, true, true); final Font font = new Font("serif", Font.PLAIN, 18); final TextLayout layout = new TextLayout("This is a test", font, frc); final Rectangle2D bounds = layout.getBounds(); System.err.println((int) (bounds.getWidth() + .5));}其次,可以通过使用ComponentListener通知组件何时可见,但这对于在“
advance”中测量字符串不是必需的!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)