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 6185025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:38:26+00:00 2026-05-24T01:38:26+00:00

The following code shows a dialog as expected, apart from having no buttons: final

  • 0

The following code shows a dialog as expected, apart from having no buttons:

  final JPasswordField passwdField = new JPasswordField();
  passwdField.setColumns(20);
  final JComponent[] inputs = new JComponent[] {  passwdField };
  int res = JOptionPane.showOptionDialog(null, "Enter Password", "Login", 
                  JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, 
                  null, inputs, "");

shows the following dialog (Java 6.2?, Windows 7 64-Bit):

enter image description here

Why are there no OK / Cancel button? (btw, the dialog is not resizable, so I don’t know if they are just outside the visible frame)

(Also, pressing Enter does not close the dialog, “x” closes the dialog)

  • 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-24T01:38:27+00:00Added an answer on May 24, 2026 at 1:38 am

    Your problem is with the inputs array. Read the API and it will tell you that it should be different. I usually use an array of String, each String representing a button String, or sometimes I use a mixture of Objects, mixing components and Strings. For e.g.,

      JPasswordField passField = new JPasswordField(10);
      Object[] inputs = {passField, "OK", "Cancel"};
      int res = JOptionPane.showOptionDialog(null, "Enter Password", "Login", 
               JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, 
               null, inputs, "");
      if (res == 1) {
         System.out.println("Password is: " + new String(passField.getPassword()));
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following piece of code shows an Insert table dialog: Dialog d = WordApp.Dialogs[WdWordDialog.wdDialogTableInsertTable];
In the following code, the first log statement shows a decimal as expected, but
I am using the following code in my project. The print dialog shows, but
I have the following code that shows a jquery ui dialog form with data
I am trying to use jquery dialog, but the following code shows 0, 1
Okay, so I've got the following code shown below to create a dialog using
I am using the following code to show a jQuery UI dialog when the
I'm using the following code in an attempt to show a dialog with a
The following code shows a button that allows you to select a file (should
I have the following code that shows either a bug or a misunderstanding on

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.