Un alternativa meno drastica (con InputVerifier l'utente è bloccato nella casella finché non "risponde correttamente") è settare un Document al JPasswordField:
Documentazione: http://docs.oracle.com/javase/6/docs...nDocument.htmlcodice:JPasswordField passwordField = new JPasswordField(); passwordField.setDocument(new PlainDocument() { @Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { try { Integer.parseInt(str); super.insertString(offs, str, a); } catch (NumberFormatException ex) { // fregate di quello che accade qui System.out.println("not a number"); } } });