Draw Beautiful Speech Bubbles in Swing [closed]

╄→гoц情女王★ 提交于 2019-11-29 05:14:47

finally I draw it with GeneralPath...

close enough? :))

@Override
protected void paintComponent(final Graphics g) {
    final Graphics2D graphics2D = (Graphics2D) g;
    RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    qualityHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    graphics2D.setRenderingHints(qualityHints);
    graphics2D.setPaint(new Color(80, 150, 180));
    int width = getWidth();
    int height = getHeight();
    GeneralPath path = new GeneralPath();
    path.moveTo(5, 10);
    path.curveTo(5, 10, 7, 5, 0, 0);
    path.curveTo(0, 0, 12, 0, 12, 5);
    path.curveTo(12, 5, 12, 0, 20, 0);
    path.lineTo(width - 10, 0);
    path.curveTo(width - 10, 0, width, 0, width, 10);
    path.lineTo(width, height - 10);
    path.curveTo(width, height - 10, width, height, width - 10, height);
    path.lineTo(15, height);
    path.curveTo(15, height, 5, height, 5, height - 10);
    path.lineTo(5, 15);
    path.closePath();
    graphics2D.fill(path);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!