getGraphics()何时会返回有效的图形实例?

getGraphics()何时会返回有效的图形实例?,第1张

getGraphics()何时会返回有效的图形实例?

首先,您可以使用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”中测量字符串不是必需的!



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5565659.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-14
下一篇2022-12-14

发表评论

登录后才能评论

评论列表(0条)

    保存