java.awt.event.KeyEvent.setKeyChar()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(3.7k)|赞(0)|评价(0)|浏览(199)

本文整理了Java中java.awt.event.KeyEvent.setKeyChar()方法的一些代码示例,展示了KeyEvent.setKeyChar()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。KeyEvent.setKeyChar()方法的具体详情如下:
包路径:java.awt.event.KeyEvent
类名称:KeyEvent
方法名:setKeyChar

KeyEvent.setKeyChar介绍

[英]Set the keyChar value to indicate a logical character.
[中]

代码示例

代码示例来源:origin: stackoverflow.com

textField.addKeyListener(new KeyListener(){

 public void keyTyped(KeyEvent e) {
  char c = e.getKeyChar();
   if (c== ',')
    e.setKeyChar('.');
 }
});

代码示例来源:origin: stackoverflow.com

class KeyListeningTool extends KeyAdapter {

  @Override
  public void keyTyped(KeyEvent evt) {
    if (evt.getKeyChar() == ',') {
      evt.setKeyChar('.');
    }
  }
}

代码示例来源:origin: stackoverflow.com

jTextField.addKeyListener(new KeyAdapter() {

 public void keyTyped(KeyEvent e) {
  char keyChar = e.getKeyChar();
  if (Character.isLowerCase(keyChar)) {
   e.setKeyChar(Character.toUpperCase(keyChar));
  }
 }

});

代码示例来源:origin: stackoverflow.com

JTextField txtFirstName = new JTextField();
txtFirstName.addKeyListener(new KeyAdapter() {
  @Override
  public void keyTyped(KeyEvent arg0) {
    char charecter = arg0.getKeyChar();
      if (Character.isLowerCase(charecter)) {
        arg0.setKeyChar(Character.toUpperCase(charecter));
      }
    }
  });

代码示例来源:origin: stackoverflow.com

KeyboardFocusManager kfm = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager();
kfm.addKeyEventDispatcher(new KeyEventDispatcher() {
  @Override
  public boolean dispatchKeyEvent(KeyEvent e) {
    if (DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == jfxPanel) {
      if (e.getID() == KeyEvent.KEY_TYPED && e.getKeyChar() == 10) {
        e.setKeyChar((char) 13);
      }
    }
    return false;
  }
});

代码示例来源:origin: org.jclarion/clarion-runtime

@Override
  public void keyTyped(KeyEvent e) {
    if (!e.isConsumed()) {
      char c = e.getKeyChar();
      c = Character.toUpperCase(c);
      e.setKeyChar(c);
    }
  }
});

代码示例来源:origin: stackoverflow.com

KeyEvent ke = new KeyEvent(<various parameters>);
ke.setKeyChar('a');
int code = ke.getKeyCode();

代码示例来源:origin: stackoverflow.com

private void jTextFieldKeyTyped(java.awt.event.KeyEvent evt) {
  if (!Character.isAlphabetic(evt.getKeyChar()) && !Character.isSpaceChar(evt.getKeyChar())) {
    evt.consume();
  } else if (jTextField.getText().trim().length() == 0 && Character.isLowerCase(evt.getKeyChar())) {
      evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
  }
}

代码示例来源:origin: gurkenlabs/litiengine

@Override
public void keyTyped(KeyEvent e) {
 // limit tags to MAX_TAG_LENGTH characters
 if (textFieldInput.getText() != null && textFieldInput.getText().length() >= MAX_TAG_LENGTH) {
  e.consume();
 }
 final char c = e.getKeyChar();
 if (!(Character.isAlphabetic(c) || Character.isDigit(c) || c == '_' || c == KeyEvent.VK_MINUS || c == KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE)) {
  e.consume();
 }
 // force lower case for tags
 if (Character.isAlphabetic(c)) {
  e.setKeyChar(Character.toLowerCase(e.getKeyChar()));
 }
}

代码示例来源:origin: net.sf.jt400/jt400

e.setKeyChar(Character.toUpperCase(c));
return;

代码示例来源:origin: org.jclarion/clarion-runtime

char c = e.getKeyChar();
c = Character.toUpperCase(c);
e.setKeyChar(c);
  e.setKeyChar(c);
} else {
  c = Character.toLowerCase(c);
  e.setKeyChar(c);

代码示例来源:origin: stackoverflow.com

e.setKeyChar(Character.toUpperCase(c));

代码示例来源:origin: mikera/tyrant

/**
 * Simulate a key press
 * Useful for handling equivalent mouse clicks
 */ 
public static void simulateKey(char c) {
  if (getUserinterface() != null) {
    KeyEvent k = new KeyEvent(getMappanel(), 0, System.currentTimeMillis(),
        0, 0, 'c');
    k.setKeyChar(c);
    getUserinterface().go(k);
  }
}

代码示例来源:origin: stackoverflow.com

if (k != CHAR_UNDEFINED) {
  if (Character.isLetter(k)) {
    e.setKeyChar(Character.toUpperCase(e.getKeyChar()));
  } else if (e.getModifiers() == 0){
    Character mapping = keyMap.get(e.getKeyCode());
    if (mapping != null) {
      e.setKeyChar(mapping);
char k = e.getKeyChar();
if (k != CHAR_UNDEFINED) {
  e.setKeyChar(lastMappedKey);
char k = e.getKeyChar();
if (k != CHAR_UNDEFINED) {
  e.setKeyChar(lastMappedKey);
  this.lastMappedKey=CHAR_UNDEFINED;

相关文章