Example usage for java.awt.event KeyEvent consume

List of usage examples for java.awt.event KeyEvent consume

Introduction

In this page you can find the example usage for java.awt.event KeyEvent consume.

Prototype

public void consume() 

Source Link

Document

Consumes this event so that it will not be processed in the default manner by the source which originated it.

Usage

From source file:controlador.ControladorReportes.java

@Override
public void keyTyped(KeyEvent e) {
    System.out.println(e.getKeyChar());
    if (!Character.isDigit(e.getKeyChar())) {
        System.out.println(e.getKeyChar());
        e.consume();
    }/*from  w w w  .  j  a  v a  2s .co m*/
}

From source file:PruebaMixto.java

private void txt_aKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_aKeyTyped
    // TODO add your handling code here:
    char a = evt.getKeyChar();
    if (a < '0' || a > '9') {
        evt.consume();
    }//from   www  . jav a2 s  . co m
}

From source file:PruebaMixto.java

private void txt_cKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_cKeyTyped
    // TODO add your handling code here:
    char a = evt.getKeyChar();
    if (a < '0' || a > '9') {
        evt.consume();
    }//from w  ww  .  ja v  a 2  s  . c  o m
}

From source file:PruebaMixto.java

private void txt_xKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_xKeyTyped
    // TODO add your handling code here:
    char a = evt.getKeyChar();
    if (a < '0' || a > '9') {
        evt.consume();
    }/*w ww  .j ava2 s  .  c  om*/
}

From source file:Console.java

public void keyPressed(KeyEvent e) {
    int code = e.getKeyCode();
    if (code == KeyEvent.VK_BACK_SPACE || code == KeyEvent.VK_LEFT) {
        if (outputMark == getCaretPosition()) {
            e.consume();
        }/*from w w  w . java  2 s  .  co m*/
    } else if (code == KeyEvent.VK_HOME) {
        int caretPos = getCaretPosition();
        if (caretPos == outputMark) {
            e.consume();
        } else if (caretPos > outputMark) {
            if (!e.isControlDown()) {
                if (e.isShiftDown()) {
                    moveCaretPosition(outputMark);
                } else {
                    setCaretPosition(outputMark);
                }
                e.consume();
            }
        }
    } else if (code == KeyEvent.VK_ENTER) {
        returnPressed();
        e.consume();
    } else if (code == KeyEvent.VK_UP) {
        historyIndex--;
        if (historyIndex >= 0) {
            if (historyIndex >= history.size()) {
                historyIndex = history.size() - 1;
            }
            if (historyIndex >= 0) {
                String str = history.elementAt(historyIndex);
                int len = getDocument().getLength();
                replaceRange(str, outputMark, len);
                int caretPos = outputMark + str.length();
                select(caretPos, caretPos);
            } else {
                historyIndex++;
            }
        } else {
            historyIndex++;
        }
        e.consume();
    } else if (code == KeyEvent.VK_DOWN) {
        int caretPos = outputMark;
        if (history.size() > 0) {
            historyIndex++;
            if (historyIndex < 0) {
                historyIndex = 0;
            }
            int len = getDocument().getLength();
            if (historyIndex < history.size()) {
                String str = history.elementAt(historyIndex);
                replaceRange(str, outputMark, len);
                caretPos = outputMark + str.length();
            } else {
                historyIndex = history.size();
                replaceRange("", outputMark, len);
            }
        }
        select(caretPos, caretPos);
        e.consume();
    }
}

From source file:vistas.ModPersonal.java

private void txt_DniMKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_DniMKeyTyped
    char car = evt.getKeyChar();
    if (txt_DniM.getText().length() >= 9) {
        JOptionPane.showMessageDialog(this, "Permitido hasta 8 digitos");
        evt.consume();
    }/*from  w  w  w  .  jav a 2 s . co  m*/
    if ((car < '0' || car > '9')) {
        JOptionPane.showMessageDialog(this, "Solo numeros");
        evt.consume();
    }
}

From source file:vistas.ModPersonal.java

private void txt_horaMKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_horaMKeyTyped
    char car = evt.getKeyChar();
    if (txt_horaM.getText().length() >= 8) {
        JOptionPane.showMessageDialog(this, "Permitido hasta 8 digitos");
        evt.consume();
    }// w  w  w. j ava 2s  .  c o  m
    if ((car < '0' || car > '9') && (car != (char) KeyEvent.VK_BACK_SPACE)) {
        JOptionPane.showMessageDialog(this, "Solo numeros");
        evt.consume();
    }

}

From source file:vistas.GestionPersonal.java

private void txt_DniKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_DniKeyTyped
    char car = evt.getKeyChar();
    if (txt_Dni.getText().length() >= 9) {
        JOptionPane.showMessageDialog(this, "Permitido hasta 8 digitos");
        evt.consume();
    }//w w  w.  j a  va 2  s .c om
    if ((car < '0' || car > '9')) {
        JOptionPane.showMessageDialog(this, "Solo numeros");
        evt.consume();
    }
}

From source file:vistas.GestionPersonal.java

private void txt_horaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_horaKeyTyped
    char car = evt.getKeyChar();
    if (txt_hora.getText().length() >= 8) {
        JOptionPane.showMessageDialog(this, "Permitido hasta 8 digitos");
        evt.consume();
    }/*from  w w  w  .  j a  v a 2 s  .c  o m*/
    if ((car < '0' || car > '9') && (car != (char) KeyEvent.VK_BACK_SPACE)) {
        JOptionPane.showMessageDialog(this, "Solo numeros");
        evt.consume();
    }

}

From source file:schoolsystem.FeePanel.java

private void txt_fee_noKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_fee_noKeyTyped
    if (evt.getKeyChar() < '0' || evt.getKeyChar() > '9') {
        Toolkit.getDefaultToolkit().beep();
        evt.consume();
    }// www.  j  av  a  2s  .c o m
}