Пример #1
0
 protected void processKeyEvent(final KeyEvent e) {
   int id = e.getID();
   switch (id) {
     case KeyEvent.KEY_TYPED:
       KeyEventCZ loKey = new KeyEventCZ(e.getKeyChar());
       moTipo.getTecla(super.getText(), loKey);
       e.setKeyChar(loKey.getKeyChar());
       break;
     case KeyEvent.KEY_PRESSED:
       if (e.getKeyCode() == e.VK_ENTER) {
         e.setKeyCode(0);
         transferFocus();
       }
       if (e.getKeyCode() == e.VK_ESCAPE) {
         e.setKeyCode(0);
         moTipo.restaurarTexto();
         super.setText(moTipo.getText());
       }
       break;
     case KeyEvent.KEY_RELEASED:
       break;
     default:
   }
   super.processKeyEvent(e);
 }
Пример #2
0
  public void keyTyped(KeyEvent e) {
    char code = e.getKeyChar();
    if (code == e.VK_ENTER) {
      //      if (dataField != null)
      {
        e.setKeyChar(e.CHAR_UNDEFINED);
        e.setKeyCode(-1);

        // only fire this event, if the data has been changed
        if (textField.isDataChanged()) {
          fireActionPerformed("enter");
        }

        // not shift + enter => focus to next
        if ((e.getModifiers() & e.SHIFT_MASK) != e.SHIFT_MASK) {
          this.changeFocusToNext();
        }
      }
    } else {
      if (!TKeyLock.keys.isLocked()) {
        textField.setDataChanged(true);
      }
    }
  }