title: How to ignore the key press event in Swing?
body: <p>I want to make the text field only accept numeric and backspace button from the user.</p>
  
  <p>I have added the function that use to check the keycode from the user, but I don't know how to stop the key press event if the keycode is not numeric. </p>
  
  <p>What code do I need to add into the function to stop the event??</p>
  
  <pre><code> private void jTextField2KeyPressed(java.awt.event.KeyEvent evt)   
   {                                       
  
     if(!((evt.getKeyCode()==8) || (evt.getKeyCode()&gt;48 &amp;&amp; evt.getKeyCode()&lt;57)))
     {
        //how to stop the key pressed event
     }
   }
  </code></pre>