Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PositiveIntegerField in SCJD book

 
Ronald Wouters
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I was using a JFormattedTextField with a MaskFormatter having a mask of "#####" (five digits) to enter the server port number until I noticed the following odd behavior :
If you do a setValue(1099) on this field, then initially the cursor is positioned before the first character : '<cursorHere>1099'.
If you then try to change the value by simply trying to overwrite the existing characters nothing happens. The cursor doesn't move and nothing is overwritten ! It is as if the field is not editable.
However, if you then move the cursor until it is after the last character like this : '1099<cursorHere>' , then all of a sudden you can add a fifth digit like this : '10995<cursorHere>'. At this point you can move the cursor back to the first digit '<cursorHere>10995' and now it IS possible to overwrite the first digits like this '88888<cursorHere>'
Has anyone else noticed this kind of behavior ?
Is this perhaps the reason why in the SCJD book the authors created the custom textfield called PositiveIntegerField (extends JTextField) instead of using a JFormattedTextField with a MaskFormatter ?

Regards, Ronald.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic