Java tutorial
//package com.java2s; //License from project: Open Source License import javax.swing.*; import javax.swing.event.DocumentListener; public class Main { /** * Adds input validator to text fields. * * @param inputValidator input validator * @param textFields text fields */ public static void addInputValidator(final DocumentListener inputValidator, final JTextField... textFields) { for (final JTextField textField : textFields) { textField.getDocument().addDocumentListener(inputValidator); } } }