This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Set range value for JTextField? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Set range value for JTextField?" Watch "Set range value for JTextField?" New topic
Author

Set range value for JTextField?

Tran Tuan Hung
Ranch Hand

Joined: Apr 08, 2007
Posts: 59
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

Joined: Oct 14, 2002
Posts: 8764
    
    5
Hi Tran,

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

Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
use a JSpinner
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
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


You down with OOP? Yeah you know me!
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
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 ]

bitguru blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Set range value for JTextField?
 
Similar Threads
How to verify input in the JTextField?
minimum float/double
JTABLE + JTEXTFIELD....
Retaining Focus in Swing
creating array to hold long range values