title: how to validate a jtextfield to accept only integer numbers
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/11093326/restricting-jtextfield-input-to-integers">Restricting JTextField input to Integers</a><br>
    <a href="https://stackoverflow.com/questions/14305921/detecting-jtextfield-deselect-event">Detecting JTextField “deselect” event</a>  </p>
  </blockquote>
  
  
  
  <p>i need to validate a <code>JTextField</code> by allowing the user to input only integer values in it if user enters any char other than numbers a <code>JOptionPane.show</code> messagebox should appear showing that the value entered are incorrect and only integer numbers are allowed. I have coded it for a  digit values but i also need to discard the alphabets</p>
  
  <pre><code>public void keyPressed(KeyEvent EVT) {
      String value = text.getText();
      int l = value.length();
      if (EVT.getKeyChar() &gt;= '0' &amp;&amp; EVT.getKeyChar() &lt;= '9') {
          text.setEditable(true);
          label.setText("");
      } else {
          text.setEditable(false);
          label.setText("* Enter only numeric digits(0-9)");
      }
  }
  </code></pre>