Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7057791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:01:58+00:00 2026-05-28T04:01:58+00:00

JOptionPane can be used to get string inputs from user, but in my case,

  • 0

JOptionPane can be used to get string inputs from user, but in my case, I want to display a password field in showInputDialog.

The way I need is the input given by the user should be masked and the return value must be in char[]. I need a dialog box with a message, password field, and two buttons. Can that be done? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:01:58+00:00Added an answer on May 28, 2026 at 4:01 am

    Yes, it is possible using JOptionPane.showOptionDialog(). Something like this:

    JPanel panel = new JPanel();
    JLabel label = new JLabel("Enter a password:");
    JPasswordField pass = new JPasswordField(10);
    panel.add(label);
    panel.add(pass);
    String[] options = new String[]{"OK", "Cancel"};
    int option = JOptionPane.showOptionDialog(null, panel, "The title",
                             JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE,
                             null, options, options[1]);
    if(option == 0) // pressing OK button
    {
        char[] password = pass.getPassword();
        System.out.println("Your password is: " + new String(password));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if there is a JOptionPane where you can get multiple inputs
I can't seem to get the password and user name on my Java JTextfield
I'm using JOptionPane.showMessageDialog(null,e,Invalid Name,JOptionPane.ERROR_MESSAGE) method to display the exception extended from Exception class. But
I want to make an input form in Java so that the user can
The following segment of code shows JOptionPane.showInputDialog() method. It works fine, Now I want
So I have the method JOptionPane.showInputDialog() which returns a String that is the value
Following situation: I have a JFrame and call JOptionPane.showInputDialog(test) . The modal dialog will
How can I add a clickable URL into a JOptionPane (in the middle of
I've created a JOptionPane as a selection method. I want the int value for
This is my first time using a JFrame. I can't get the window to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.