• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextField + Listener

 
Remi Dubey
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I ha some jtfs(JTextFeilds) say, jtf1, jtf2 in jp3(JPanels) say, jp1, jp2, and jp3.
I hv used addActionListener for all the abv jtfs.
whnever i change any value of any of the jtfs i hv to press "ENTER" key of the keyboard to save the changes to these jtfs.
Is there any method by wch i can add such a listener by wch i need not press "ENTER" key to save the changes to jtfs.
i tried using textValueChanged and keyListeners too!!!
pl. reply as early as possible....
thnax
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Remi,
Welcome to GUI design. It depends on what your application expects and what you want people to do ...
If you have n textfields that all must be filled in and then some apply button hit to perform an action, you could have the apply button listener perform the text validations.
If you are trying to limit what a user types in any textfield then you will have to look into PlainDocument class. It has a method that gets called for every insertion into the field.
If a textfield depends on another you may want to use FocusListener so you can compare the results from the losing textfield and validate then.
There is really no right or wrong way, at least until your users complain, then one way might be better than the next ...
Regards,
Manfred.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!