Here you can find the source of setNumericAndCharOnly(final javax.swing.JTextField textField)
public static void setNumericAndCharOnly(final javax.swing.JTextField textField)
//package com.java2s; //License from project: Apache License import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; public class Main { public static void setNumericAndCharOnly(final javax.swing.JTextField textField) { textField.addKeyListener(new KeyAdapter() { @Override// ww w. j a va 2 s. c o m public void keyTyped(KeyEvent evt) { if (!Character.isLetterOrDigit(evt.getKeyChar())) { evt.consume(); } } }); } }