Class PasswordDialog

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public class PasswordDialog extends JDialog
A modal dialog that asks the user for a user name and password. More information about this class is available from ostermiller.org.
 PasswordDialog p = new PasswordDialog(null, "Test");
 if(p.showDialog()){
     System.out.println("Name: " + p.getName());
     System.out.println("Pass: " + p.getPass());
 } else {
     System.out.println("User selected cancel");
 }
 
Since:
ostermillerutils 1.00.00
Author:
Stephen Ostermiller https://ostermiller.org/contact.pl?regarding=Java+Utilities
See Also:
  • Constructor Details

    • PasswordDialog

      public PasswordDialog(Frame parent, String title)
      Create this dialog with the given parent and title.
      Parameters:
      parent - window from which this dialog is launched
      title - the title for the dialog box window
      Since:
      ostermillerutils 1.00.00
    • PasswordDialog

      public PasswordDialog(Frame parent)
      Create this dialog with the given parent and the default title.
      Parameters:
      parent - window from which this dialog is launched
      Since:
      ostermillerutils 1.00.00
    • PasswordDialog

      public PasswordDialog()
      Create this dialog with the default title.
      Since:
      ostermillerutils 1.00.00
  • Method Details

    • setLocale

      public void setLocale(Locale locale)
      Set the locale used for getting localized strings.
      Overrides:
      setLocale in class Component
      Parameters:
      locale - Locale used to for i18n.
      Since:
      ostermillerutils 1.00.00
    • setName

      public void setName(String name)
      Set the name that appears as the default An empty string will be used if this in not specified before the dialog is displayed.
      Overrides:
      setName in class Component
      Parameters:
      name - default name to be displayed.
      Since:
      ostermillerutils 1.00.00
    • setPass

      public void setPass(String pass)
      Set the password that appears as the default An empty string will be used if this in not specified before the dialog is displayed.
      Parameters:
      pass - default password to be displayed.
      Since:
      ostermillerutils 1.00.00
    • setOKText

      public void setOKText(String ok)
      Set the label on the OK button. The default is a localized string.
      Parameters:
      ok - label for the ok button.
      Since:
      ostermillerutils 1.00.00
    • setCancelText

      public void setCancelText(String cancel)
      Set the label on the cancel button. The default is a localized string.
      Parameters:
      cancel - label for the cancel button.
      Since:
      ostermillerutils 1.00.00
    • setNameLabel

      public void setNameLabel(String name)
      Set the label for the field in which the name is entered. The default is a localized string.
      Parameters:
      name - label for the name field.
      Since:
      ostermillerutils 1.00.00
    • setPassLabel

      public void setPassLabel(String pass)
      Set the label for the field in which the password is entered. The default is a localized string.
      Parameters:
      pass - label for the password field.
      Since:
      ostermillerutils 1.00.00
    • getName

      public String getName()
      Get the name that was entered into the dialog before the dialog was closed.
      Overrides:
      getName in class Component
      Returns:
      the name from the name field.
      Since:
      ostermillerutils 1.00.00
    • getPass

      public String getPass()
      Get the password that was entered into the dialog before the dialog was closed.
      Returns:
      the password from the password field.
      Since:
      ostermillerutils 1.00.00
    • okPressed

      public boolean okPressed()
      Finds out if user used the OK button or an equivalent action to close the dialog. Pressing enter in the password field may be the same as 'OK' but closing the dialog and pressing the cancel button are not.
      Returns:
      true if the the user hit OK, false if the user canceled.
      Since:
      ostermillerutils 1.00.00
    • showDialog

      public boolean showDialog()
      Shows the dialog and returns true if the user pressed ok.
      Returns:
      true if the the user hit OK, false if the user canceled.
      Since:
      ostermillerutils 1.00.00