Java JOptionPane Prompt promptForDecryptionPassword()

Here you can find the source of promptForDecryptionPassword()

Description

prompt For Decryption Password

License

GNU General Public License

Declaration

private static String promptForDecryptionPassword() 

Method Source Code


//package com.java2s;
// Licensed under GPL v3.0; see LICENSE for full text

import java.awt.GridLayout;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;

public class Main {
    private static String promptForDecryptionPassword() {
        // Set up custom JPanel with masked password field
        JPanel decryptionPasswordInputPanel = new JPanel(new GridLayout(1, 2));
        JPasswordField decryptionPasswordPrompt = new JPasswordField();
        decryptionPasswordInputPanel.add(new JLabel("Enter decryption password:"));
        decryptionPasswordInputPanel.add(decryptionPasswordPrompt);

        // Prompt for decryption password
        int result = JOptionPane.showConfirmDialog(null, decryptionPasswordInputPanel, "Decryption Password",
                JOptionPane.OK_CANCEL_OPTION);
        if (result == JOptionPane.OK_OPTION) { // OK selected
            return new String(decryptionPasswordPrompt.getPassword());
        } else { // Dialog cancelled
            return null;
        }/*  ww  w. j a v  a  2 s.c om*/
    }
}

Related

  1. askYesNo(String title, String prompt, Object... args)
  2. promptForDatsDir(Component parentComponent)
  3. promptForDelete(Component c, String title, String prompt)
  4. promptForDelete(Component c, String title, String prompt)
  5. showDbxAccessDeniedPrompt()