Package com.Ostermiller.util
Class PasswordDialog
java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Window
java.awt.Dialog
javax.swing.JDialog
com.Ostermiller.util.PasswordDialog
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible,RootPaneContainer,WindowConstants
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.awt.Dialog
Dialog.ModalExclusionType, Dialog.ModalityTypeNested classes/interfaces inherited from class java.awt.Window
Window.TypeNested classes/interfaces inherited from class java.awt.Component
Component.BaselineResizeBehavior -
Field Summary
Fields inherited from class java.awt.Dialog
DEFAULT_MODALITY_TYPEFields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE -
Constructor Summary
ConstructorsConstructorDescriptionCreate this dialog with the default title.PasswordDialog(Frame parent) Create this dialog with the given parent and the default title.PasswordDialog(Frame parent, String title) Create this dialog with the given parent and title. -
Method Summary
Modifier and TypeMethodDescriptiongetName()Get the name that was entered into the dialog before the dialog was closed.getPass()Get the password that was entered into the dialog before the dialog was closed.booleanFinds out if user used the OK button or an equivalent action to close the dialog.voidsetCancelText(String cancel) Set the label on the cancel button.voidSet the locale used for getting localized strings.voidSet the name that appears as the default An empty string will be used if this in not specified before the dialog is displayed.voidsetNameLabel(String name) Set the label for the field in which the name is entered.voidSet the label on the OK button.voidSet the password that appears as the default An empty string will be used if this in not specified before the dialog is displayed.voidsetPassLabel(String pass) Set the label for the field in which the password is entered.booleanShows the dialog and returns true if the user pressed ok.Methods inherited from class javax.swing.JDialog
getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setTransferHandler, updateMethods inherited from class java.awt.Dialog
addNotify, getModalityType, getTitle, hide, isModal, isResizable, isUndecorated, setBackground, setModal, setModalityType, setOpacity, setResizable, setShape, setTitle, setUndecorated, setVisible, show, toBackMethods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, removeNotify, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImage, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, toFrontMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validateMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setMaximumSize, setMixingCutoutShape, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
PasswordDialog
Create this dialog with the given parent and title.- Parameters:
parent- window from which this dialog is launchedtitle- the title for the dialog box window- Since:
- ostermillerutils 1.00.00
-
PasswordDialog
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
Set the locale used for getting localized strings. -
setName
Set the name that appears as the default An empty string will be used if this in not specified before the dialog is displayed. -
setPass
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
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
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
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
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
Get the name that was entered into the dialog before the dialog was closed. -
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
-