Significant performance differences in JTextPane when text contains linefeed <p>I wrote a method that writes <em>hello world!\n</em> 10000 times in a JTextPane. I recognized a significant performance drop when using <em>hello world!</em> without linefeed.</p> <p>Example:</p> <pre><code>import java.awt.BorderLayout; import javax.swing.*; import javax.swing.text.*; public class JTextPaneTest { JTextPane textPane = new JTextPane(); Document doc = new DefaultStyledDocument(); //constructor JTextPaneTest() { for(int i=0;i&lt;10000;i++) { try { doc.insertString(doc.getLength(), i+" hello world!", null); } catch (BadLocationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } textPane.setDocument(doc); createWindow(); } public void createWindow() { JFrame frame = new JFrame(); frame = new JFrame("frame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 300); frame.setLocationRelativeTo(null); frame.getContentPane().add(new JScrollPane(textPane), BorderLayout.CENTER); frame.setVisible(true); } public static void main(String[] args) { System.out.println("start..."); float startTime = System.nanoTime(); new JTextPaneTest(); float stopTime = System.nanoTime() - startTime; System.out.println("elapsed time main: "+stopTime/1000000000+ "s"); } } </code></pre> <p>what could be the reason for that phenomena? Any ideas?</p>