Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to restrict data in JTextField?  RSS feed

 
Bob Zoloman
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or a JCombobox, perhaps?
 
John Bartlett
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!