sendText.addKeyListener(new KeyListener(){
public void keyPressed(KeyEvent e) {
if(e.keyCode == SWT.CR){
//让按键原有的功能失效
e.doit = false;
//执行你自己的事件
MessageBox box = new MessageBox(new Shell(), SWT.ICON_INFORMATION | SWT.OK);
box.setText("提示信息");
box.setMessage("按回车键了");
box.open();
}
}
public void keyReleased(KeyEvent e) {}
});
完整示例
Color red = display.getSystemColor(SWT.COLOR_RED);
Font font = display.getSystemFont();
control.setFont(font)
Style | Description |
---|---|
SWT.WRAP | Wrap the text to fit the visible area |
SWT.LEFT | Left-align the label |
SWT.CENTER | Center-align the label |
SWT.RIGHT | Right-align the label |
SWT.SEPARATOR | Draw a separator instead of text or an image |
SWT.HORIZONTAL | Draw the separator horizontally |
SWT.VERTICAL | Draw the separator vertically |
SWT.SHADOW_IN | Draw the separator with a "shadow in" effect |
SWT.SHADOW_OUT` | Draw the separator |
键盘事件类型
SWT.KeyDown | A key was pressed | ||
SWT.KeyUp | A key was released |
KeyEvent | KeyListener (and KeyAdapter) | keyPressed(KeyEvent) keyReleased(KeyEvent) |
关于event中的character特殊键值
SWT.BS | 退回 ('/b') |
SWT.CR | 回车 ('/r') |
SWT.DEL | 删除 ('/u007F') |
SWT.ESC | ESC ('/u001B') |
SWT.LF | 换行 ('/n') |
SWT.TAB | TAB跳格 ('/t') |
SWT.CONTROL | <Ctrl>同 SWT.CTRL |
SWT.SHIFT | <Shift> |
SWT.ALT | <Alt> |