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:Main.java

public static KeyListener maxLength(JTextComponent textComponent, int length) {
    return new KeyAdapter() {
        @Override//from   w w w.ja  v  a  2 s.com
        public void keyTyped(KeyEvent e) {
            if (textComponent.getText().length() >= length) {
                e.consume();
                textComponent.setText(textComponent.getText().substring(0, length));
            }
        }
    };
}

From source file:Main.java

/**
 * Set the text component in which only numerics (positive decimal integers
 * with character 0-9)./*  ww w .j av  a  2s.com*/
 * 
 * @param c
 *            the specified text component
 */
public static void setTextComponetIntegerValid(final JTextComponent c) {
    c.addKeyListener(new KeyAdapter() {
        @Override
        public void keyTyped(KeyEvent e) {
            if (e.getKeyChar() != KeyEvent.VK_BACK_SPACE)
                try {
                    Integer.valueOf(c.getText() + e.getKeyChar());
                } catch (NumberFormatException nfe) {
                    e.consume();
                    Toolkit.getDefaultToolkit().beep();
                }
        }
    });
}

From source file:com.SCI.centraltoko.utility.UtilityTools.java

private static void batasInput(JTextField textFIle, KeyEvent keyEven, int maxIsi) {
    if (textFIle.getText().length() + 1 > maxIsi) {
        keyEven.consume();
    }/*from w w  w.ja  va  2s .  c  o  m*/
}

From source file:com.SCI.centraltoko.utility.UtilityTools.java

public static void setNumericTextOnly(final JTextField textField) {
    textField.addKeyListener(new KeyAdapter() {

        @Override// w  w w.j av  a2 s  .c  om
        public void keyTyped(KeyEvent e) {
            if (!Character.isDigit(e.getKeyChar()) || BAD_CHARS.indexOf(e.getKeyChar()) > -1) {
                e.consume();
            }
        }

    });

}

From source file:org.nekorp.workflow.desktop.view.resource.imp.MonedaTextField.java

public MonedaTextField() {
    super();//from  www  .j av  a 2s .co  m
    this.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
            char car = e.getKeyChar();
            if (car != '.') {
                if ((car < '0' || car > '9')) {
                    e.consume();
                }
            } else {
                if (StringUtils.contains(getText(), '.')) {
                    e.consume();
                }
            }
        }

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
        }
    });
}

From source file:SimpleInputMethod.java

public void dispatchEvent(AWTEvent event) {
    if (event.getID() == KeyEvent.KEY_TYPED) {
        KeyEvent e = (KeyEvent) event;
        if (handleCharacter(e.getKeyChar())) {
            e.consume();
        }/*from  www .  j a va 2s  .  co m*/
    }
}

From source file:ve.zoonosis.controller.seguridad.LoginController.java

private void iniciarSesion(KeyEvent evt) {
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        evt.consume();
        iniciarSesion();/*from   ww w . ja v a  2s .  c  om*/
    }
}

From source file:org.nekorp.workflow.desktop.view.binding.MonedaBindableJTextField.java

public MonedaBindableJTextField() {
    super();/*from   ww  w.  ja  va  2 s  .co  m*/
    ignore = new LinkedList<>();
    this.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
            char car = e.getKeyChar();
            if (car != '.') {
                if ((car < '0' || car > '9')) {
                    e.consume();
                }
            } else {
                if (StringUtils.contains(getText(), '.')) {
                    e.consume();
                }
            }
        }

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
        }
    });
}

From source file:MyKeyListener.java

public void keyTyped(KeyEvent evt) {
    JTextComponent c = (JTextComponent) evt.getSource();
    char ch = evt.getKeyChar();

    if (Character.isLowerCase(ch) == false) {
        return;//  www .j  ava 2  s .  c  om
    }
    try {
        c.getDocument().insertString(c.getCaretPosition(), "" + Character.toUpperCase(ch), null);
        evt.consume();
    } catch (BadLocationException e) {
    }
}

From source file:vistas.Login.java

private void txt_userKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_userKeyTyped
    char car = evt.getKeyChar();
    if (txt_user.getText().length() >= 11) {
        evt.consume();
    }// w  ww.  ja v  a 2s .  c  o  m
}