 <p>The <code>drawString</code> method does not handle new-lines.</p> <p>You'll have to split the string on new-line characters yourself and draw the lines one by one with a proper vertical offset:</p> <pre><code>void drawString(Graphics g, String text, int x, int y) { for (String line : text.split("\n")) g.drawString(line, x, y += g.getFontMetrics().getHeight()); } </code></pre> <hr> <p>Here is a complete example to give you the idea:</p> <pre><code>import java.awt.*; public class TestComponent extends JPanel { private void drawString(Graphics g, String text, int x, int y) { for (String line : text.split("\n")) g.drawString(line, x, y += g.getFontMetrics().getHeight()); } public void paintComponent(Graphics g) { super.paintComponent(g); drawString(g, "hello\nworld", 20, 20); g.setFont(g.getFont().deriveFont(20f)); drawString(g, "part1\npart2", 120, 120); } public static void main(String s[]) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new TestComponent()); f.setSize(220, 220); f.setVisible(true); } } </code></pre> <p>which gives the following result:</p> <p><img src="https://i.stack.imgur.com/l8x9w.png" alt="enter image description here"></p>