title: How to intercept keyboard strokes going to Java Swing JTextField?
body: <p>The JTextField is a calculator display initialized to zero and it is bad form to display a decimal number with a leading 0 like 0123 or 00123. The numeric buttons (0..9) in a NetBeans Swing JFrame use append() [below] to drop the leading zeros, but the user may prefer the keyboard to a mouse, and non-numeric characters also need to be handled.</p>
  
  <pre><code>private void append(String s) {
      if (newEntry) {
          newEntry = false;
          calcDisplay.setText(s);
      } else if (0 != Float.parseFloat(calcDisplay.getText().toString())) {
          calcDisplay.setText(calcDisplay.getText().toString() + s);
      }
  }
  </code></pre>