UnixPasswordField

You're looking for a unix style password input field in Java Swing? Such as in the terminal, where no echo characters (● or *) are displayed? Here you are!

If you don't know what I mean with 'unix style password input', try this in the Linux Bash:


read -sp "Password: " VARIABLE
echo $VARIABLE
					

It's a password input with absolutely no feedback to the user (except the key clatter).

I've looked for such a password field, but couldn't find one on the web (Oct. 2012). So I wrote this one, extending the JPasswordField:

I didn't go deep into the Swing Framework for this, so it is probably not a perfect solution. But I think it works well so far. Copy/Cut/Paste is disabled, control keys (such as Enter and Tab) do what they are usually doing and finally all characters and Backspace affect the password. For a few more details, read the Javadoc.

An example using it:


UnixPasswordField pwField = new UnixPasswordField();
// Same action as for the login button:
pwField.setAction(loginAction);
pwField.addFocusListener(new FocusAdapter() {
	@Override
	public void focusGained(FocusEvent e) {
		pwField.clear();
		// And show some hint for the user,
		// that the password is cleared.
	}
});
					

Download: Here on GitHub

Copyright © 2013 Jakob Schöttl  |  2013-12-21