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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:38:32+00:00 2026-05-25T12:38:32+00:00

Basically I wan’t to obtain a string from the user, I have created a

  • 0

Basically I wan’t to obtain a string from the user, I have created a class called “frames” in which I have a load of methods such as exitChoice(), infoPop(), ect… I wish to create one called getText(), and this is what I have so far:

        public String getText()
        {
            JDialog textBox = new JDialog(frame, "Save Name", true);

            JTextField inputField = new JTextField(18);
            inputField.setText(save == null ? "new save" : save.saveName);

            textBox.setBounds(width, height, 275, 70);
            textBox.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            textBox.setLayout(new FlowLayout());
            textBox.setAlwaysOnTop(true);
            textBox.setResizable(false);
            textBox.add(inputField);
            textBox.setVisible(true);

            return inputField.getText();
        }

now I know this won’t work, It simply gets the game stuck and I have to terminate it externally, I also understand why it doesn’t work, that isn’t the problem, I also know how to add a JButton, an action listener and work it from there,

Basically I am trying to create a clean simple method which obtains a String from the user which is ALL contained within the method.

Ideally I would like to write a line which reads along the lines of

//EDIT: I know the method getText() does exist, sorry if it is misleading, I will ammend it

//String saveName = new JTextField.getText();
String saveName = new JTextInputGetterBoxThing();

but as far as I have found so far this doesn’t appear to exist, does anybody have any ideas? or ideally know of a one liner that I have missed?

  • 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-25T12:38:33+00:00Added an answer on May 25, 2026 at 12:38 pm

    I think what you want is the JOptionPane.showInputDialog method. Something like this?

    public class GetUserInput {
    
        public static String getUserInput() {
            return JOptionPane.showInputDialog("Type Something");
        }
    
        public static void main(String[] args) {
            System.out.println("User Input: " + getUserInput());
        }
    }
    

    This shows a dialog with the prompt “Type Something” and a text field for entry. Whatever the user types in the text field is returned by getUserInput().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I have an entity (called Session) which will provide many different Services. Each
I want to create string ENUM in c#. Basically i wan't to set form
Basically I have 2 strings. They are EXACTLY the same string. However, when I
Basically in my in my aspx page I have a gridview which displays the
I wan an array which is going to have about 30 things in it.
Basically I have two models: User and Godfather. The godfather table has three columns:
Basically I have, typedef map<std::string, set<double> > MAP_STRING_TO_SET; What is the best way to
Basically, I have the following code: public class MyDictionary<TKey, TValue> : IDictionary<TKey, TValue> {
Basically I have some code to check a specific directory to see if an
Basically I am trying to restart a service from a php web page. Here

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.