Disable "insert" in jText field

I have an application written in Swing, awt. I want users not to insert values ​​into text fields. is there any way to do this without using action listeners?

+3
source share
5 answers

You can simply call setTransferHandler with a null parameter, for example:

textComponent.setTransferHandler(null);

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

+15
source

The best way is to remove the action associated with pressing CTRL + V in the ActionMap components.

+5
source

: textComponent.setEditable(false);

, - .

+1
public class PastlessJTextField extends JTextField {

        public PastlessJTextField() {
            super();
        }
        public PastlessJTextField( int columns ){
            super( columns );
        }

        @Override
        public void paste() {
            // do nothing
        }


    }
+1

paste() JTextComponent.

0

All Articles