Java摆动HTML drawString

Java摆动HTML drawString,第1张

Java摆动HTML drawString

我找到了一种简洁的模拟方法

paintHtmlString
; 这是代码

public class MyComponent extends JComponent {    private JLabel label = null;    public MyComponent() {        super();    }    private JLabel getLabel() {        if (label == null) { label = new JLabel();        }        return label;    }        private void paintHtmlString(Graphics g, String html, int x, int y) {        g.translate(x, y);        getLabel().setText(html);        //the fontMetrics stringWidth and height can be replaced by        //getLabel().getPreferredSize() if needed        getLabel().paint(g);        g.translate(-x, -y);    }    protected void paintComponent(Graphics g) {        //some drawing operations...        paintHtmlString(g, "<html><u>some text</u></html>", 10, 10);    }}


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

原文地址: https://outofmemory.cn/zaji/5508955.html

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

发表评论

登录后才能评论

评论列表(0条)

保存