Detecting user updates to a text field

I have a JTextField which I want to update automatically when another field changes.

This much is easy, but I think if the user makes a change to the text field themselves, that I should stop doing the automatic updates. So I need a way to listen for user changes to the text field.

KeyListener doesn't really work because if the user pastes or drags text into the field, it won't pick that up. DocumentListener doesn't really work because my automatic updates then get picked up and the flag gets turned off prematurely.

Is there something in-between?

[580 byte] By [trejkaza] at [2007-11-27 6:39:40]
# 1

> I have a JTextField which I want to update automatically when another > field changes.

i ever see an application that auto updating textfield and stop when that textfield grab focus. (Edit: you can change your application behaviour like this by set off the flag when focus gained. if focus lost and user do nothing, it's up to you to resume auto-updating or not).

in your case, you user won't have enoght time to type, if your auto-updating run in a short time interval.

if that data is very critical, than you should seperate it in a label.

Message was edited by:

j_shadinata

j_shadinataa at 2007-7-12 18:08:51 > top of Java-index,Desktop,Core GUI APIs...
# 2

> KeyListener doesn't really work because if the user pastes...

remove that option

JTextField tf = new JTextField(10){

public void paste(){}

};

Michael_Dunna at 2007-7-12 18:08:51 > top of Java-index,Desktop,Core GUI APIs...
# 3

Aha, that's a good idea. I'll just flag it off when they focus the text field. That should be good enough because I'll start focus on the field before it.

The way the events work, I should get the "other component changed its value" event before the "focus moved" event, so it should be safe time-wise, since all events occur on the same thread.

trejkaza at 2007-7-12 18:08:51 > top of Java-index,Desktop,Core GUI APIs...