I am trying to simulate text input in a JTextField I have a 1 letter long string in which I want to add letters and I run:
receiver.dispatchEvent (new keyEvent (this, KeyEvent.KEY_TYPED, 0, this.shifted? KeyEvent. SHIFT_DOWN_MASK: 0, Key Event. VK_UNDEFINED, text.charAt (0))); But this does not seem to change the content at all. What am I missing here?
I look like a virtual keyboard: -)
almost the exact same Code works for me I give the following suggestions:
-
target
JTextField(in your case,receiver) to < Code> pass as sourcekeyEventparameter for constructor, i.e.:receiver. DisketAvent (New keyEvent (Receiver, KeyWorld.ktttd, system.contentime milliseconds), Modifier, -
Ensure that your target is
JTextFieldCon Structureer), it works fine:Edit:
To verify the above suggestions, Tested this snippet for:
code> KeyEventframe frame = new frame (); textfield text = new textfield (); frame.ed (text); Ram.pack (); frame.Seasible (true) text; dislike event (new key event (frame, key event, keiPED, 0, 0, key events, this does not work, however The last line has been modified as follows (if the target component is the parameter of thesource, then it is not working;text.dispatchEvent (new keyEvent (text, keyEvent.KEY_TYPED, 0, 0, keyEvent.VK_UNDEFINED, 'H'));
Comments
Post a Comment