title: how to prevent the JTextField from counting the backspace
body: <p>I am trying to make sure that the user enters a strong password in the JTextField. however, it works good but it counts the backspace, shift, and ctrl when clicked</p>
  <pre><code>            public void keyPressed(KeyEvent e) {
              // if else make sure that the user do not enter space
              if (Character.isWhitespace(e.getKeyChar())) {
                  passwordMessage.setText(&quot;spaces are not allowed!!&quot;);
                  passwordtext.setEditable(false);
              } else {
                  passwordMessage.setText(&quot;&quot;);
                  passwordtext.setEditable(true);
              }
              
              // if elseif else to make sure that the user enter a good length
              // passwordtext.getText().length() does not count the first entered so I -1 from the length
              if(passwordtext.getText().length() &gt;= 14) { // if length is 15 or above
                  passwordMessage.setForeground(Color.GREEN);
                  passwordMessage.setText(&quot;password is Strong&quot;);              
              }
              else if(passwordtext.getText().length() &gt;= 7) { // if length is 8 or above
                  passwordMessage.setForeground(Color.ORANGE);
                  passwordMessage.setText(&quot;password is Good&quot;);
              }
              else if(passwordtext.getText().length() &lt; 7) { // if length is less than 8
                  passwordMessage.setForeground(Color.RED);
                  passwordMessage.setText(&quot;minimum password is 8 letters or digits!!&quot;);
              }
              else if(passwordtext.getText().length() == 0) { // setting the label text to be empty
                  passwordMessage.setText(&quot;&quot;);
              }
          }
  </code></pre>
  <p>-for example, if the user typed 12345678 the &quot;password is Good&quot; will appear in the label but if he clicked backspace and removed the 8 the &quot;password is Good&quot; will still appear in the label because it removed the 8 but added the click of the backspace so the length is still 8</p>
  <p>-same thing happened when the user type 1234567 and then click ctrl the &quot;password is Good&quot; will appear because it counts the click of the ctrl</p>