title: Restricting access to some lines in JTextArea?
body: <p>I wanted to make a JTextArea where the user can't erase the previous line. Just like the Command Prompt in Windows and the terminal in Linux, you can't edit previous lines.</p>
  
  <p>This is what I've come up with, but it doesn't seem to work, and I can only come up with one reason for this, but it appears to be more than just one reason.</p>
  
  <pre><code>if(commandArea.getCaretPosition() &lt; commandArea.getText().lastIndexOf("\n")){
          commandArea.setCaretPosition(commandArea.getText().lastIndexOf("\n"));
  }
  </code></pre>
  
  <p>This block of code lives inside this method:</p>
  
  <pre><code>private void commandAreaKeyPressed(java.awt.event.KeyEvent evt)
  </code></pre>