JtextArea Key Filter

I want to filter the keystrokes on a JTextArea so that certain characters won't be displayed.

I tried to dispatch a backspace after the filtered characters using:

console.dispatchEvent(new KeyEvent( sp, KeyEvent.KEY_PRESSED , System.currentTimeMillis(), 0, KeyEvent.VK_BACK_SPACE, (char) 8));

But I couldn't get it to work.

How can I achieve this?

Thanks,

[460 byte] By [Beavis111a] at [2007-10-3 8:31:02]
# 1
Not sure if this is what youre looking for, but you might want to try a [url http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JPasswordField.html]JPasswordField[/url].
CaptainMorgan08a at 2007-7-15 3:38:07 > top of Java-index,Desktop,Core GUI APIs...
# 2

> so that certain characters won't be displayed.

If the character is stored in the Document, then it will be displayed unless you write a custom view.

If you want to prevent the character from being added to the Document then you should use a [url http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html#filter]DocumentFilter[/url].

camickra at 2007-7-15 3:38:07 > top of Java-index,Desktop,Core GUI APIs...