• Post Reply Bookmark Topic Watch Topic
  • New Topic

JFormattedTextField and negative numbers

 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am unable to find any resource that describes how JFormattedTextField will behave if user inputs a negative number. I am using following code:


Thanks for your help.
Barkat
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can limit or constrain the allowable input to a JFormattedTextField with a either a DocumentFilter or a custom Formatter. The Formatter can use a DocumentFilter and/or override the valueToString and stringToValue methods to achieve this. The java tutorial has an example of using a DocumentFilter. Another option is MaskFormatter which has methods that will restrict input.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!