Hi 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?
A:
Or you can:
- defined your own
PlainDocument
, then - associate it to your
JTextFiled
, and - override in your
PlainDocument
theinsertString()
method
The insertString
Method will only insert anything if the custom attribute 'enablePaste
' that you will have defined in this custom PlainDocument
class is true.
VonC
2008-11-25 09:10:23
+2
A:
The best way is to remove action associated with CTRL+V keystroke in components ActionMap.
Rastislav Komara
2008-11-25 11:08:55
A:
The simplest way it to say: textComponent.setEditable(false);
This disables cut & paste, but copy is still enabled.
- Rob, PhD
Rob
2010-02-26 17:36:28