Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Updating based on user editing value in JTextField

paultaylorJun 18 2007 — edited Jun 18 2007
I have a Swing application. The top half uses a JTable to show a list of records. the bottom half shows details of the currently selected record as a series of JTextFields, this is correctly updated through use of a ListSelectionListener.

Now want a user to be able to edit a field in the bottom half and when they leave the (JTextField) field the record as shown in the datasheet should be updated to reflect the changes. I dont want them to have to press an Ok button. Ive looked at a few ways of doing this but none of them seem quite right, what is the correct way to do this?

First of all I tried adding a Document Listener to the documents returned by the JTextField, but the trouble was that I was unable to distinguish between a record changing due to a user edit and a record changing due to the user selecting another record in the table. Even if I could distinguish between the two I was receiving a load of events I wasn't interested in.

I then looked at using an ActionListener, but this only triggers when the user presses the Enter key, I want it to trigger when they tab out or use the Mouse to move the focus. Also the documentation seemed to imply using of ActionListeners for this sort of thing was the old way of doing things and was there to provide backwards compatability. I could use KeyListeners and FocusListeners as well but it all seems very low level.

I then read about InputVerifiers, as I understand it this would trap the user leaving a field they have edited. But arent they for validating input rather than what I want to do.

thanks Paul
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 16 2007
Added on Jun 18 2007
7 comments
273 views