Forums Register Login

JTextField & Keylistener

+Pie Number of slices to send: Send
Ciao,
problem:
I added the KeyListener to my JTextField and when insert a text and I confirm, it triggers an event programmed by me. So everything is right. But if I do the setText ("Hello"); course it breaks loose keyPressed event



how do I invoke the KeyEvent with the setText?
1
+Pie Number of slices to send: Send
Hi Robert, and welcome to the Ranch!

For the purpose you describe, you should be using a DocumentListener or a Document Filter -- not a KeyListener.
1
+Pie Number of slices to send: Send
Also don't listen for the Enter key. Instead you should add an ActionListener to the text field.
+Pie Number of slices to send: Send
have you an example?
1
+Pie Number of slices to send: Send
Have you come across this tutorial? Various sections of it are linked from tha API documentation of just about any Swing class.
Creating a GUI With JFC/Swing

There's a ton of example code there.
If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 814 times.
Similar Threads
keyboard events
want to do some action when input is typed in Swing JPanel components
JTextField - Restrict length
Probelm with KeyListener
What is wrong with this code?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 03:58:08.