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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:20:37+00:00 2026-05-30T08:20:37+00:00

Ok, I’m trying to make a quick double validator for any JTextField in a

  • 0

Ok, I’m trying to make a quick double validator for any JTextField in a program. I would like to pass this to a function which then checks the contents of a field, makes sure it’s a double, then return it as a double to the function.

Here is what I have so far but theTF.getValue() should get the value of the string, not the string itself.

    public double valDouble(String theTF)
    {
            double theDouble;
            try
            {
                theDouble = theTF.getValue();
                return theDouble;
            }
    }

How can I run the getValue() on the contents of the string?

Edit:
Ok, I somewhat screwed up my meaning. I understand the parseDouble, but I left it out on accident here is what I have now:

    public static double valDouble(String theTF)
    {
        double theDouble;
        try
        {
            theDouble = Double.parseDouble(theTF);
        }
        catch(NumberFormatException e3)
        {
            theDouble = 0;
        }
        return theDouble;

    }

My Real issue is theTF represents the name of a TextField. I need the value OF the text field not the value in theTF. I’d like to have this here to, perhaps, highlight the field red etc.

Answer(Thanks Hunter):
The best way was to pass the Object, not sure why I was trying to parse out the value of a string reference.

    public static double vDbl(JTextField theTF)
    {
        double theDouble;
        try
        {
            theDouble = Double.parseDouble(theTF.getText());
        }
        catch(NumberFormatException e3)
        {
            theTF.setText("Invalid");
            return 0;
        }
        return theDouble;
    }
  • 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-30T08:20:38+00:00Added an answer on May 30, 2026 at 8:20 am

    You should really be passing the JTextField object to your method to get the information you are looking for, I don’t even know if it’s possible to get the JTextField object from just its name; maybe with reflection, but for this application reflection seems overly complex.

    ex:

    public double valDouble(JTextField theTF)
    {
            try
            {
                return Double.parseDouble(theTF.getText());
            }
            catch(NumberFormatException nfe)
            {
                System.err.println(nfe.getMessage());
            }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to understand how to use SyndicationItem to display feed which is
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to render a haml file in a javascript response like so:
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small

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.