Java JTextField textAreaChangeListener(JTextField a, final ChangeListener list)

Here you can find the source of textAreaChangeListener(JTextField a, final ChangeListener list)

Description

Reroute all document changes to a change listener

License

BSD License

Declaration

public static void textAreaChangeListener(JTextField a,
        final ChangeListener list) 

Method Source Code

//package com.java2s;
/***/*from   ww w .  j a  va 2  s.c  o m*/
 * Copyright (C) 2010 Johan Henriksson
 * This code is under the Endrov / BSD license. See www.endrov.net
 * for the full text and how to cite.
 */

import javax.swing.*;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

public class Main {
    /**
     * Reroute all document changes to a change listener
     */
    public static void textAreaChangeListener(JTextArea a,
            final ChangeListener list) {
        a.getDocument().addDocumentListener(new DocumentListener() {
            public void change() {
                list.stateChanged(null);
            }

            public void changedUpdate(DocumentEvent e) {
                change();
            }

            public void removeUpdate(DocumentEvent e) {
                change();
            }

            public void insertUpdate(DocumentEvent e) {
                change();
            }
        });
    }

    /**
     * Reroute all document changes to a change listener
     */
    public static void textAreaChangeListener(JTextField a,
            final ChangeListener list) {
        a.getDocument().addDocumentListener(new DocumentListener() {
            public void change() {
                list.stateChanged(null);
            }

            public void changedUpdate(DocumentEvent e) {
                change();
            }

            public void removeUpdate(DocumentEvent e) {
                change();
            }

            public void insertUpdate(DocumentEvent e) {
                change();
            }
        });
    }
}

Related

  1. setText(JTextField jField, Object pObject, Object pDefault)
  2. setupNoCommitCheckbox(final JCheckBox addLogInformationCheckBox, final JTextField commitMessage, final JCheckBox noCommitCheckBox)
  3. setupTextField(JPanel panel, JLabel label, JTextField field, long val, String toolTip)
  4. setValue(JTextField f, String value)
  5. showFileOpenDialogAndChangePrefs(String prefName, FileNameExtensionFilter fileNameExtensionFilter, JTextField textField, Class forClass, Component parent)
  6. toUpperCase(JTextField field)
  7. triggerTextField(JTextField textField, JCheckBox checkBox)
  8. upperText(JTextField text)
  9. validateJTextField(JTextField text, Component aThis)