Here's a solution that uses JOptionPane
to display a JPasswordField
that prints spaces as the user types.
Indeed, all you would like to put in your code is the showPasswordPrompt()
method, but the code includes the main()
method, which allows you to easily check how the dialog box looks.
import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPasswordField; public class JOptionPaneTest { public static String showPasswordPrompt( Component parent, String title ) {
source share