Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-20-2007, 12:15 PM
Member
 
Join Date: May 2007
Posts: 2
nemo is on a distinguished road
How to determine if the value of a JTextField is double
I have a textfield and i want it to have only double values. How can i make sure of this?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-20-2007, 12:19 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
Double has parseDouble method which tries to parse a String as a Double. You need to put it inside a try-catch block since it throws NumberFormatException.

You can write logic inside catch since it is called if the value is not a valid double!

Here is an example code:

Code:
double value; try { // String textValue = the string from your JTextField value = Double.parseDouble(textValue); // if the code gets to here, it was recognizable as a double } catch(NumberFormatException e) { // if the code gets to here, it was NOT recognizable as a double }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to focus to another JTextfield? birdofprey AWT / Swing 2 04-09-2008 02:08 PM
How to determine all the IP addresses of machines on local LAN?? JavaEmpires Networking 3 01-19-2008 07:05 AM
How to determine CPU usage using Java????? JavaEmpires New To Java 2 01-11-2008 12:19 AM
how to determine the primary key osval Database 1 08-07-2007 03:31 AM
help with JTextfield gary New To Java 4 07-11-2007 02:58 PM


All times are GMT +3. The time now is 03:31 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org