/** * Shows a dialog requesting input from the user parented to {@code parentComponent} with the dialog having the title {@code title} and message type {@code messageType}. * * @param parentComponent the parent {@code Component} for the dialog * @param message the {@code Object} to display * @param title the {@code String} to display in the dialog * title bar * @param messageType the type of message that is to be displayed: * {@code ERROR_MESSAGE}, * {@code INFORMATION_MESSAGE}, * {@code WARNING_MESSAGE}, * {@code QUESTION_MESSAGE}, * or {@code PLAIN_MESSAGE} * @return An {@link Optional} holding the password if the dialog was confirmed, otherwise {@link Optional#empty()}. * @throws HeadlessException if {@code GraphicsEnvironment.isHeadless} returns {@code true} * @see java.awt.GraphicsEnvironment#isHeadless */ public static Optional<char[]> showPasswordDialog(@Nullable final Component parentComponent, final Object message, final String title, final int messageType) { final JPasswordField jPasswordField = new JPasswordField(); jPasswordField.addAncestorListener(FocusRequestingAncestorListener.INSTANCE); return OK_OPTION == showConfirmDialog(parentComponent, new Object[]{message, jPasswordField}, title, OK_CANCEL_OPTION, messageType) ? Optional.of(jPasswordField.getPassword()) : Optional.empty(); }
if (isPassword) { JPasswordField pwd = new JPasswordField(); pwd.addAncestorListener(new RequestFocusListener()); int action = JOptionPane.showConfirmDialog(null, pwd, label, JOptionPane.OK_CANCEL_OPTION); if (action == JOptionPane.OK_OPTION) {
if (isPassword) { JPasswordField pwd = new JPasswordField(); pwd.addAncestorListener(new RequestFocusListener()); int action = JOptionPane.showConfirmDialog(null, pwd, label, JOptionPane.OK_CANCEL_OPTION); if (action == JOptionPane.OK_OPTION) {
passwordField.addAncestorListener(new RequestFocusListener()); JOptionPane.showConfirmDialog(null, new Object[]{label, passwordField}, Res.getString("title.password.required"), JOptionPane.OK_CANCEL_OPTION); password = new String(passwordField.getPassword());