java代码获取文本的高度和宽度

       String name="我是谁?";

        Font font = new Font("微软雅黑", Font.PLAIN, 26);
        FontMetrics fm = FontDesignMetrics.getMetrics(font);
        int txt_w = fm.stringWidth(name);//文字的宽度

        int txt_h=fm.getHeight();//文字高度

猜你喜欢

转载自zhousheng193.iteye.com/blog/2234747
今日推荐