Kevin Snow
Wed, 11 Jun 2003 07:30:04 -0700
Here is some code that should do what you want:
JPasswordField passwordField = new JPasswordField(20);
JOptionPane optionPane = new JOptionPane();
optionPane.setMessage( new Object[] { "Please
enter a password:", passwordField } );
optionPane.setMessageType(
JOptionPane.QUESTION_MESSAGE );
optionPane.setOptionType(
JOptionPane.OK_CANCEL_OPTION );
JDialog dialog = optionPane.createDialog( this,
"Password" );
dialog.show();
Integer value = (Integer)optionPane.getValue();
if ( value == null || value.intValue() ==
JOptionPane.CANCEL_OPTION
|| value.intValue() ==
JOptionPane.CLOSED_OPTION )
{
dialog.dispose();
return;
}
System.out.println("Password = " +
passwordField.getPassword());
dialog.dispose();
-----Original Message----- From: Sachin Hejip [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 11, 2003 9:39 AM To: Salome Harrison; [EMAIL PROTECTED] Subject: Re: JOptionPane and passwords Hey, You can pass a JPasswordField as the message parameter. >From the JavaDoc of JOptionPane :- the parameter message can take the following types of values - message A descriptive message to be placed in the dialog box. In the most common usage, message is just a String or String constant. However, the type of this parameter is actually Object. Its interpretation depends on its type: Object[] An array of objects is interpreted as a series of messages (one per object) arranged in a vertical stack. The interpretation is recursive -- each object in the array is interpreted according to its type. Component The Component is displayed in the dialog. Icon The Icon is wrapped in a JLabel and displayed in the dialog. others The object is converted to a String by calling its toString method. The result is wrapped in a JLabel and displayed. Hope this helps Regards Sachin ----- Original Message ----- From: "Salome Harrison" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, June 11, 2003 6:57 PM Subject: JOptionPane and passwords > Hi all, > > Currently I am using the JOptionPane.showInputDialog > to get a single input from the user. > > This is what I have: > > value = JOptionPane.showInputDialog(this, "Enter > something", JOptionPane.QUESTION_MESSAGE, null, null, > null); > > For one instance I need to ask the user for a password > before I execute a script for them. So, I need to not > display the password as they type it. Will > setEchoChar("*") work and if so how do I set that for > the TextField in the JOptionPane. If that is not the > best way, can someone please give me some guidance? > > Thanks, > Salome > > > __________________________________ > Do you Yahoo!? > Yahoo! Calendar - Free online calendar with sync to Outlook(TM). > http://calendar.yahoo.com > _______________________________________________ > Swing mailing list > [EMAIL PROTECTED] > http://eos.dk/mailman/listinfo/swing _______________________________________________ Swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/swing _______________________________________________ Swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/swing