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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:51:10+00:00 2026-06-18T02:51:10+00:00

I was wondering how inputdialog returns value especially when there are also ok and

  • 0

I was wondering how inputdialog returns value especially when there are also ok and cancel buttons.
Could somebody explain how does it manage to return value?

UPDATE:

Let me put it this way.
I want to create a dialog with 6 buttons and each button returns different value.
And i want it get that value like this:
String value = MyDialog.getValue(); // like showInputDialog

the problem is how do i return value on button press?

  • 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-06-18T02:51:12+00:00Added an answer on June 18, 2026 at 2:51 am

    Now that I have a clearer understanding of your goal, I think instead of trying to emulate JOptionPane, it would be easier to just give each button a different actionCommand:

    private JDialog dialog;
    
    private String inputValue;
    
    String showPromptDialog(Frame parent) {
        dialog = new JDialog(parent, true);
        dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    
        // [add components to dialog here]
    
        firstButton.setAction(new ButtonAction("Button 1",  "first"));
        secondButton.setAction(new ButtonAction("Button 2", "second"));
        thirdButton.setAction(new ButtonAction("Button 3",  "third"));
        fourthButton.setAction(new ButtonAction("Button 4", "fourth"));
        fifthButton.setAction(new ButtonAction("Button 5",  "fifth"));
        sixthButton.setAction(new ButtonAction("Button 6",  "sixth"));
    
        dialog.pack();
        dialog.setLocationRelativeTo(parent);
    
        inputValue = null;
        dialog.setVisible(true);
    
        return inputValue;
    }
    
    private class ButtonAction
    extends AbstractAction {
        private static final long serialVersionUID = 1;
    
        ButtonAction(String text,
                     String actionCommand) {
            super(text);
            putValue(ACTION_COMMAND_KEY, actionCommand);
        }
    
        public void actionPerformed(ActionEvent event) {
            inputValue = event.getActionCommand();
            dialog.dispose();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Wondering if someone could please explain the difference between these two queries and advise
Wondering if someone with experience could possibly explain this a bit more. I have
Wondering if someone could help me. I have next to no knowledge with Ajax,
Wondering if there is any way to get the lambda expressions that result from
Wondering if there is a good way to generate temporary URLs that expire in
wondering if there is a way to do the following: I basically want to
Wondering if anyone out there might know a trick to a small sql script.
Wondering what a continue statement does in a do...while(false) loop, I mocked up a
Wondering if there is any way to build and fire an event (e.g. on
Wondering if there is any php script out there which takes an sql db

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.