Search code examples
javaswinggraphics2d

Draw heart symbol with drawString


I've tried ♡, and \u2661 as text but I'm unable to draw the heart symbol.

g2d.setColor(Color.RED);
g2d.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 70));
g2d.drawString(text, 10, 10);

Solution

  • You can try to use \u2665 instead of \u2661. Simply do:

    g.setColor(Color.RED);
    g.drawString("\u2665", 10, 10);
    

    \u2665 is the unicode for heart shape. For reference:

    ♥ \u2665
    ♦ \u2666
    ♣ \u2663
    ♠ \u2660