JPasswordField passwordField = new JPasswordField(8);passwordField.setEchoChar('*');add the passwordField to your JFrame or JPanel, etc.....String password = new String(passwordField.getPassword());