This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

textbox validation

 
Jeff Ciaccio
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I've got a text box that expects a double between 0.1 and 0.99. I would like to validate this right when the user enters the number and then tries to change the focus to another component. Is there data validation built in to Java? NetBeans?

Thanks,
Jeff
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of text box is it? Swing? HTML?
 
Jeff Ciaccio
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
swing.
JTextField
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One option is use a JFormattedTextField instead. Another is use an InputVerifier.
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like something which would sit better on the Swing forum. Moving.
 
Jeff Ciaccio
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm very green with Java, so I just wanted to do something simple like:
1) cast the text as double (but I'm not sure how)
2) do an if then to check:
if (txt > double is < 0.1 or > .99) then set focus back on textBox and change the label's font color to red and bold
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this out to get an idea of how it's usually done.
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't "cast" text to a double. You can however use a Double class method whihc parses the String as a double.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic