Just paste into a JTextField

0

I need to do in Java, that in a JTextField only data can be copied, that is:

  • not allow data to be entered directly from the keyboard
  • just allow a data to be copied from another side and pasted into the JTextField.

Is this possible?

    
asked by Carolina garcia montoya 03.11.2017 в 14:04
source

2 answers

1

JTextField by default creates a keymap interface also referenced as DEFAULT_KEYMAP . A Keymap (shared by all instances JTextComponent ) allows an application to join keystrokes to actions; Within those minimum actions are:

  • Insert content in the field when it comes to keys printable.
  • Delete content with the Backspace or Del keys.
  • Move the blinking cursor forward or backward.
  • Passing null to setKeymap() is inactive the keyboard entry but still with the ability to paste the data from the clipboard.

    miCampo.setKeymap(null);

    Source: Documentation of JTextComponent .

        
    answered by 03.11.2017 / 17:22
    source
    0

    can be done by the method:

    jTextField = new JTextField();
    jTextField.setEditable(false); //no permite editar "a mano", pero si copiar
    jTextField.setText("test2"); // ejemplo de edición aceptado
    
        
    answered by 03.11.2017 в 16:40