Is there any listener or event to check latest time user input in JTextField
? I want to call a function whenever user stop input in n seconds.
Asked
Active
Viewed 29 times
0

Andrew Thompson
- 168,117
- 40
- 217
- 433

Quan Nguyen
- 559
- 4
- 23
- 47
-
5Use a `DocumentListener` coupled with a Swing `Timer`. Each time the `DocumentListener` is notified, restart the `Timer`, if the `Timer` is activated, you know the timeout was exceeded – MadProgrammer Jun 03 '18 at 05:37
-
3As demonstrated [here](https://stackoverflow.com/questions/17985808/search-text-file-and-display-results-in-a-jpanel/17988175#17988175) and [here](https://stackoverflow.com/questions/31666428/action-listener-for-a-jtextfield-to-change-value-in-another-textfield/31666660#31666660) and [here](https://stackoverflow.com/questions/29644309/how-to-fixed-keylistener-on-jtextfield/29644408#29644408) and [here](https://stackoverflow.com/questions/31955193/how-to-start-a-function-after-stop-typing-in-a-jtextfield-in-java/31955279#31955279) – MadProgrammer Jun 03 '18 at 05:39
-
3and [here](https://stackoverflow.com/questions/29224709/jtextarea-scroll-to-bottom-only-if-text-is-appended/29224842#29224842) and [here](https://stackoverflow.com/questions/42874743/is-it-possible-that-after-typing-a-value-in-jtextfield-it-will-automatically-pre/42881562#42881562) and [here](https://stackoverflow.com/questions/12751706/fetch-data-from-database-into-jtextfield-when-one-jtextfield-is-typed/12754738#12754738) and [here](https://stackoverflow.com/questions/29500713/overlay-swing-text-label-as-text-is-entered/29506154#29506154) – MadProgrammer Jun 03 '18 at 05:41
-
@MadProgrammer Could any of those answers be a duplicate of this one? – Andrew Thompson Jun 03 '18 at 05:42
-
@AndrewThompson Since the OP hasn't provided much context, frankly, they all could be - but I'm been nice, as people seem to get up set when I hammer close their questions :/ – MadProgrammer Jun 03 '18 at 05:42
-
I think it's actually best to wait a bit before hammering a question closed. Sometimes they do come back and provide additional context. It can be very difficult to get a request to re-open a question through ime. @MadProgrammer – markspace Jun 03 '18 at 05:45
-
@MadProgrammer *"people seem to get up set when I hammer close their questions"* Yeah .. I don't (seem to) mind when people get their knickers in a knot, but I could not be bothered wading through 8 answers trying to find the best one to close as duplicate. ;) Maybe your advice in the first comment & links will help the OP solve this & avoid the need for further action. – Andrew Thompson Jun 03 '18 at 05:46
-
Hi all, thanks for your support. I think I will use a Timer to solve my case. I am newbier in JFrame so do not familiar with all comcepts – Quan Nguyen Jun 03 '18 at 05:56
-
Take a look at this answer: https://stackoverflow.com/questions/48905884/how-to-get-time-between-mouse-moves/48907847#48907847 It has demonstrated a similar concept for not moving the mouse more than a certain time interval. As @MadProgrammer said it couples a Swing Timer with a mouseListener. You just need to get the idea of **resetting the timer** every time a `DocumentEvent` happens. Then replace the `MouseListener` with `DocumentListener` as mentioned by @MadProgrammer. – STaefi Jun 03 '18 at 05:58
-
1@AndrewThompson Trying "not" to seem "unfriendly" :P – MadProgrammer Jun 03 '18 at 06:00