Java JOptionPane Message requestPassword(String titulo, String msg)

Here you can find the source of requestPassword(String titulo, String msg)

Description

request Password

License

Open Source License

Declaration

public static String requestPassword(String titulo, String msg) 

Method Source Code


//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;
        }
    }
}

Related

  1. promptForFloat(Component parentComponent, String message, String title, float oldValue)
  2. promptForString(Component parentComponent, String message, String title, String oldValue)
  3. queryBoolean(String message)
  4. queryDouble(String message, double initialValue)
  5. queryInt(String message, int initialValue)
  6. select(String[] selList, String msg)
  7. show(String title, int type, Object message, Object[] options, Object initialOption)
  8. showActionFailedWithExceptionMessage(final Component parent, final Exception ex)
  9. showAlert(String message)