Java tutorial
//package com.java2s; //License from project: Open Source License import javax.swing.*; import java.awt.*; import java.awt.event.KeyAdapter; public class Main { public static JTextField createTextField(Dimension preferredSize) { return createTextField(preferredSize, null); } public static JTextField createTextField(Dimension preferredSize, KeyAdapter keyListener) { return createTextField(preferredSize, keyListener, true); } public static JTextField createTextField(Dimension preferredSize, KeyAdapter keyListener, boolean enabled) { JTextField textField = new JTextField(); textField.setPreferredSize(preferredSize); textField.addKeyListener(keyListener); textField.setEnabled(enabled); return textField; } }