Disabling 'paste' in a jTextfield

kilhra picture kilhra · Nov 25, 2008 · Viewed 9.8k times · Source

I have an app that is written in Swing, awt. I want to prevent users from pasting values into the textfields. is there any way to do this without using action listeners?

Answer

Christian picture Christian · Sep 20, 2011

You can just call setTransferHandler with a null parameter like this:

textComponent.setTransferHandler(null);

This will disable all copy/paste actions on the field.