How is it possible that if I type A in a textfield, that is added to String variable which is empty and I can then pass that string as a argument to a textfield for display what I typed.
for example:
String letter2="";
if(ke.getKeyCode()==KeyEvent.VK_A)
letter2=letter2+"a";

btextfield.setText(letter2);

Recommended Answers

All 3 Replies

the above is performed in a KeyPressed method.

instead of this:

letter2=letter2+"a";

do something like:

letter2=letter2+aTextField.getText();

  • reason why DocumentListener is implemented in JTextComponents APIs,

  • do not to use KeyListener for JTextComponents, you can'r be able to manage all KeyEvents, nor text is inserted from ClipBoard

  • there you can to append to another Document or share the same Document for two, bunch of JTextComponents, or to directly call setText(anotherJTextField.getText())

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.