Two Laptop Bag*
The moose likes Swing / AWT / SWT and the fly likes How to restrict data in JTextField? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to restrict data in JTextField?" Watch "How to restrict data in JTextField?" New topic
Author

How to restrict data in JTextField?

Bob Zoloman
Ranch Hand

Joined: Jul 02, 2006
Posts: 72
I'm trying to make a JTextField that only accepts 0 or 1, as the input. Is there any way to do this? Thanks.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
use a DocumentFilter, or, if you mean the textfield will only be 1 character (0 or 1),
perhaps a JSpinner might suit
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Or a JCombobox, perhaps?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
John Bartlett
Ranch Hand

Joined: Jan 25, 2006
Posts: 116
I suppose the only other way would be to put validation logic in the method where you use the value in the textField?

i.e



John
[ November 06, 2006: Message edited by: John Bartlett ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to restrict data in JTextField?