• Post Reply Bookmark Topic Watch Topic
  • New Topic

Universal way to detect field changes?  RSS feed

 
Phil Chuang
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to use a DocumentListener for this. Something like this:



hth
[ September 09, 2004: Message edited by: Gregg Bolinger ]
 
Phil Chuang
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you suggest for JComboBox, or other non-Text fields?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!