JTextField on Text Field Change - Java Swing

Java examples for Swing:JTextField

Description

JTextField on Text Field Change

Demo Code

/**//from   w w  w . j  a  va2 s  . c o  m
 * Copyright (C) 2010-14 pvmanager developers. See COPYRIGHT.TXT
 * All rights reserved. Use is subject to license terms. See LICENSE.TXT
 */
//package com.java2s;

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();
            }
        });
    }
}

Related Tutorials