Here you can find the source of bindPropertyChangeListener(final JTextField field, final String name, final PropertyChangeListener listener)
public static void bindPropertyChangeListener(final JTextField field, final String name, final PropertyChangeListener listener)
//package com.java2s; //License from project: LGPL import javax.swing.*; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.text.DocumentFilter; import javax.swing.text.PlainDocument; import javax.swing.text.StringContent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; public class Main { public static void bindPropertyChangeListener(final JTextField field, final String name, final PropertyChangeListener listener) { bindPropertyChangeListener(field, name, listener, null); }//from www .ja v a 2 s.co m public static void bindPropertyChangeListener(final JTextField field, final String name, final PropertyChangeListener listener, DocumentFilter documentFilter) { if (field.getDocument() == null) { field.setDocument(new PlainDocument(new StringContent())); } final PlainDocument document = (PlainDocument) field.getDocument(); if (documentFilter != null) { document.setDocumentFilter(documentFilter); } field.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { fireChangeEvent(); } @Override public void removeUpdate(DocumentEvent e) { fireChangeEvent(); } @Override public void changedUpdate(DocumentEvent e) { fireChangeEvent(); } private void fireChangeEvent() { listener.propertyChange(new PropertyChangeEvent(field, name, "", field.getText())); } }); } }