my dog learned polymorphism
The moose likes Swing / AWT / SWT and the fly likes Universal way to detect field changes? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Universal way to detect field changes?" Watch "Universal way to detect field changes?" New topic
Author

Universal way to detect field changes?

Phil Chuang
Ranch Hand

Joined: Feb 15, 2003
Posts: 251
Now, maybe this is just me, but I thought that the main field components (JTextField, JTextArea, JCheckBox, JComboBox, etc.) would've had some sort of addValueChangeListener method, that catches all data value modifications to the field - like changes to the text field, checkbox checked/unchecked, etc.

But there isn't any such thing. I've tried using ActionListener, KeyListener, ChangeListener, ItemListener, PropertyChangeListener, etc., but none of them do the trick. The closest thing I can do is use a FocusListener that compares entry/exit data values.

Is there any way I can get a listener that fires immediately upon value changes?
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15229

You need to use a DocumentListener for this. Something like this:



hth
[ September 09, 2004: Message edited by: Gregg Bolinger ]
Phil Chuang
Ranch Hand

Joined: Feb 15, 2003
Posts: 251
What do you suggest for JComboBox, or other non-Text fields?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Universal way to detect field changes?
 
Similar Threads
Comments on final server design
Validating input data passed to web service
Hardcoded fields or generated by file header?
need help with algorithm-count 1 value in two fields
Dynamic Database Scheme