public static char[] readPassword(String prompt) {
LookAndFeel currentLookAndFeel = UIManager.getLookAndFeel();
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception ex) {
}
try {
SecurePasswordInputPanel gui = new SecurePasswordInputPanel();
String[] options = new String[]{OK};
String tmpPrompt = prompt;
if (tmpPrompt == null || tmpPrompt.isEmpty()) {
tmpPrompt = "Password required";
}
int option = JOptionPane.showOptionDialog(null, gui, tmpPrompt, JOptionPane.NO_OPTION,
JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
if (option == 0) {
return gui.getPassword();
} else {
return null;
}
} finally {
try {
UIManager.setLookAndFeel(currentLookAndFeel);
} catch (UnsupportedLookAndFeelException ex) {
}
}
}