title: KeyPressedEvent to SetText for JTextArea
body: <p>I attempted to make a JTextArea in my Java.Swing application using NetBeans so that when I press the Enter Button. The JTextArea will display "BUTTON PRESSED".</p>
  
  <p>Here is what I have:</p>
  
  <pre><code>private void keyPressedEvent(java.awt.event.KeyEvent evt)
  {
      if(evt.getKeyCode() == KeyEvent.VK_ENTER)
      {
           System.out.println("HERE"); //For sanity check.
           txtArea.setText("BUTTON PRESSED");
           System.out.println("HERE AGAIN"); //For sanity check
      }
  }
  </code></pre>
  
  <p>I noticed that the print statements are executing but the txtArea is not setting the text.</p>
  
  <p>I did some research and believe that <code>evt.consume()</code> should be called somewhere, but I am unsure of how that works.</p>
  
  <p>EDIT:
  I tried putting <code>evt.consume()</code> in the <code>if-block</code> and it still did not set the text.</p>
  
  <p>Adding the key listener like this:</p>
  
  <pre><code>private void initComponents() {
  
      jScrollPane1 = new javax.swing.JScrollPane();
      jTextArea1 = new javax.swing.JTextArea();
  
      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  
      jTextArea1.setColumns(20);
      jTextArea1.setRows(5);
      jTextArea1.addKeyListener(new java.awt.event.KeyAdapter() {
          public void keyPressed(java.awt.event.KeyEvent evt) {
              KeyPressedEvent(evt);
          }
      });
      jScrollPane1.setViewportView(jTextArea1);
  
      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
              .addGap(59, 59, 59)
              .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addContainerGap(175, Short.MAX_VALUE))
      );
      layout.setVerticalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
              .addGap(40, 40, 40)
              .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addContainerGap(164, Short.MAX_VALUE))
      );
  
      pack();
  }// &lt;/editor-fold&gt;
  </code></pre>