Here you can find the source of onTextFieldChange(JTextField field, final Runnable task)
public static void onTextFieldChange(JTextField field, final Runnable task)
//package com.java2s; /**/*from w w w . j av a 2s . c o m*/ * Copyright (C) 2010-14 pvmanager developers. See COPYRIGHT.TXT * All rights reserved. Use is subject to license terms. See LICENSE.TXT */ import javax.swing.JTextField; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; public class Main { public static void onTextFieldChange(JTextField field, final Runnable task) { field.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { task.run(); } @Override public void removeUpdate(DocumentEvent e) { task.run(); } @Override public void changedUpdate(DocumentEvent e) { task.run(); } }); } }