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?
You can simply call setTransferHandler with a null parameter, for example:
textComponent.setTransferHandler(null);
This will disable all copy / paste actions in the field.
The best way is to remove the action associated with pressing CTRL + V in the ActionMap components.
: textComponent.setEditable(false);
textComponent.setEditable(false);
, - .
public class PastlessJTextField extends JTextField { public PastlessJTextField() { super(); } public PastlessJTextField( int columns ){ super( columns ); } @Override public void paste() { // do nothing } }
paste() JTextComponent.
paste()
JTextComponent