I have a routine that requests an administrators approval for access to protected data.
for security the adminsirator needs to know what data is requested.

The following routine gets the password without any problem:

    public static Boolean Confirm_Change() {
        Boolean test = false;
        JPasswordField pf = new JPasswordField();
        int okCxl = JOptionPane.showConfirmDialog(null,pf, "Administrator -- Enter your Password", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
        if (okCxl == JOptionPane.OK_OPTION) {
            String password = new String(pf.getPassword());
            if (password.equals("admin")) {
                test = true;
            } else {
                test = false;
            }
        }
        return test;
    }
What I want is to display above the password box a text field that gives a brief description of the request for access.... such as

| <user-name> is requesting access to: |
| Change Purchase order request routine |

| Please enter your password to approve |

the text portion (line2) will be passed to the routine in the calling statement. Confirm_Change(String text)

How would I go about adding this text field to a showConfirmDialog box or do I need to use another type of JOptionPane?
Thanks

well, that's not really what JOptionPane is meant for.
the best way to go is to create a simple JFrame that provides this functionality.

You are probably correct.... I have found a nice work-around tho...

    public static Boolean Confirm_Change(String Request_Type) {
        Boolean test = false;
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(4, 1));
        JLabel Line1 = new JLabel(User_Name.getText()+" Requests the following:");
        JLabel Line2 = new JLabel(Request_Type);
        JLabel Line3 = new JLabel(" Administrator -- Please enter your password to approve.");
        JPasswordField pf = new JPasswordField();
        panel.add(Line1);
        panel.add(Line2);
        panel.add(Line3);
        panel.add(pf);
        int okCxl = JOptionPane.showConfirmDialog(null,panel, "Administrator -- Enter your Password", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (okCxl == JOptionPane.OK_OPTION) {
            String password = new String(pf.getPassword());
            if (password.equals("admin")) {
                test = true;
            } else {
                test = false;
            }
        }
        return test;
    }

So far it is working.... will know for certain tomorrow after I get all of the function calls updated to send the line of text.

That's a nice demo of using a panel in a standard dialog. Thank you.

ps

 String password = new String(pf.getPassword());
 if (password.equals("admin")) {
   test = true;
 } else {
   test = false;
 }

OR just

String password = pf.getPassword();
test = password.equals("admin");

Update..... Worked like a charm!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.