Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to forbid the backspace in a JTextField?

user12076936Mar 19 2010 — edited Mar 20 2010
Hello,

I'm trying to write a JTextField KeyListener that basically consumes all backspaces, so that anything input by the user in the field cannot be cancelled. (The user doesn't setText()).

How can I do that? It seems like I cannot!

I've tried by identifying '\b' and consume the KeyEvent, but then the backspace is still executed.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 17 2010
Added on Mar 19 2010
7 comments
888 views