I'm trying to create a class that extends jTextField that closely mimicks the VB 6 MaskedEditControl. The way I'm planning to implement it is: when the user types in the textbox, I want to check the new text against the mask before showing it. It will filter out any text that does not match the mask.
The problem is, I don't know what event to use. If I use the KeyPressed or KeyTyped events, everything works fine, and I can check the text against the mask, but whatever the user had typed in shows up at the end of the textbox.
If I use the jTextField's Document's textInserted event, I can check the new text against the mask, but, when I go to put the checked text back into the textbox, it of course fires the textInserted event, and I end up in an infinate loop.
So, my question is: If I use the KeyPressed/KeyTyped event, can I somehow make it so that the Key that was Pressed/Typed is NOT inserted into the textbox? -OR- If I use the Document's textInserted event, is there a way where I can stop listening for a textInserted event while I'm changing the text, then, start listening for the textInserted event again once I'm finished?