markspace wrote :
> On 10/11/2010 11:13 AM, bruce wrote:
>
>> Thanks for the suggestion. I "Sort Of" understand what you have done.
>
>
> What John did is pretty simple. He just used the .setDocument() method of a
> JTextField to set its underlying document to one that will only allow x
> characters.
>
> One thing to be careful of when you're doing "key presses" is that I don't
> think Java passes all calls to the document .insert() method through some
> sort of key press filter.
>
> What if the key press is "Cntl-V" for example, where one key press might
> insert quite a lot of text? What if there is no key press at all, e.g. some
> one selects "Paste" from a menu?
>
> You might want to show us a bit more realistic example of what you are trying
> to do, I don't think your approach right now is guaranteed to work.
And you have to watch special operations such as "Delete" and
"Backspace". If your character count is full, you still need to allow
certain characters through.
--
Wojtek