Java JTextField Number setNumericAndCharOnly(final javax.swing.JTextField textField)

Here you can find the source of setNumericAndCharOnly(final javax.swing.JTextField textField)

Description

set Numeric And Char Only

License

Apache License

Declaration

public static void setNumericAndCharOnly(final javax.swing.JTextField textField) 

Method Source Code


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

Related

  1. getNumber(JTextField field, Integer defaultInt)
  2. largeEqualThan(javax.swing.JTextField input, double x)
  3. parseIntFromField(JTextField jField, int pDefault)
  4. placeDoubleTextInField(JTextField inField, int length, double toPlace)
  5. readDoubleFromField(JTextField inField, double defaultValue)
  6. setTextField(javax.swing.JTextField textField, double value, int precision)
  7. showInDecimalFormat(JTextField pJTextField)
  8. validateDoubleInput(Component parentComponent, JLabel label, JTextField textField, String valueDescription, String errorTitle, boolean positiveValue, boolean showMessage, boolean valid)
  9. verifyNumber_geq(JTextField field, Long number)