This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Set range value for JTextField?

 
Tran Tuan Hung
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have an JTextField and i want to fill the Integer value in this, but only in the range (30,70).
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tran,

I'm going to move this over to a more appropriate forum, thanks,

Bert
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use a JSpinner
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well,

If you have a JTextField, and you want to only allow the integer 30<INT<70

you would just have a button, and when you click it, just test the text in the jtextfield

like so:



so if it is a number, it will test it, else throw exception

Justin Fox
 
Brian Cole
Author
Ranch Hand
Posts: 902
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Justin Fox:
If you have a JTextField, and you want to only allow the integer 30<INT<70

you would just have a button, and when you click it, just test the text in the jtextfield


You could also do something like this:In some threading situations you may want to call field.commitEdit() before calling field.getValue().


You could also go with Mr. Dunn's suggestion to use JSpinner.
[ February 22, 2008: Message edited by: Brian Cole ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic