Here you can find the source of requestPassword(String titulo, String msg)
public static String requestPassword(String titulo, String msg)
//package com.java2s; //License from project: Open Source License import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPasswordField; public class Main { public static String requestPassword(String titulo, String msg) { JPanel panel = new JPanel(); JLabel label = new JLabel(msg); JPasswordField pass = new JPasswordField(10); panel.add(label);//from w w w . j ava 2 s.c o m panel.add(pass); pass.requestFocusInWindow(); String[] options = new String[] { "OK", "Cancelar" }; int option = JOptionPane.showOptionDialog(null, panel, titulo, JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[1]); if (option == 0) { char[] password = pass.getPassword(); return new String(password); } else { return null; } } }