Java Swing Key Action validarNumeroInteiro(KeyEvent evt)

Here you can find the source of validarNumeroInteiro(KeyEvent evt)

Description

validar Numero Inteiro

License

Open Source License

Declaration

public static void validarNumeroInteiro(KeyEvent evt) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.event.KeyEvent;

import javax.swing.JTextField;

public class Main {
    public static void validarNumeroInteiro(KeyEvent evt) {
        if (!Character.isDigit(evt.getKeyChar()) && evt.getKeyChar() != '-')
            evt.consume();//from   w  w  w  . java  2 s  .c  o m
        if (((JTextField) evt.getSource()).getText().length() > 0 && evt.getKeyChar() == '-')
            evt.consume();
    }
}

Related

  1. simulateKeyStrokes(Component comp, String text)
  2. stringify(KeyStroke keyStroke)
  3. stringToKey(String s)
  4. stringToKeys(String s)
  5. translate(KeyStroke keyStroke, Locale locale)