SWT 常用事件
KeyEvent
character? (Ctrl? + A , 代表的是A字符)
?The Unicode value of the character (e.g., \u0041 for A)
?
keyCode? (Ctrl + A ,? 代表的是 sWT.CTRL
?A constant indicating which key was pressed (e.g., SWT.PAGE_UP)
?
stateMask (Ctrl + A, 当没有按下 A 时, 是0, 按下后是Ctrl
?The "state mask" representing keyboard modifiers (e.g., SWT.SHIFT)
?state Mask modify key
?Table 2.5. Specific Modifier Key State Masks
?
?Modifier Mask?????????? Description
?
SWT.CONTROL????????????? The <Ctrl> key was down (same as SWT.CTRL)
?
SWT.SHIFT???????????????????? The <Shift> key was down
?
SWT.ALT???????????????????????? The <Alt> key was down
?
SWT.COMMAND??????????? The <Command> key was down (Window平台没有)
Table 2.6. Generic Modifier Key State Masks
Modifier Mask?????????????????????? Description
?
SWT.MOD1??????????????????????????? The first modifier was down (often SWT.CONTROL)
?
SWT.MOD2???????????????????????????? The second modifier was down (often SWT.SHIFT)
?
SWT.MOD3??????????????????????????? The third modifier was down (often SWT.ALT)
?
SWT.MOD4??????????????????????????? The fourth modifier was down (often zero)
?
SWT.MODIFIER_MASK??????????? Bitwise-OR of all valid modifiers
//CORRECT – works when new modifier masks are added
if ((event.stateMask & SWT.MODIFIER_MASK) == 0) {
??? System.out.println("No modifiers are down");
}
Traversal Event
有两种方式: 快捷键 和 Tab
Table 2.7. Mnemonic Strings
String????????????????? Result
?
"&File"????????????????? File
?
"T&able"????????????? Table
?
"This && That"???? This & That
Composite.setTabList() : 显示的设置Compostie 中控件的table ordering.
Table 2.9. Public Fields of Class Event Valid during SWT.Traverse
Field????????????????????????? Description
?
detail???????????????????????? The traversal code
?
doit??????????????????????????? Setting doit to false cancels the traversal operation. The default value indicates whether the particular traversal operation would
????????????????????????????????? normally be performed by the control. For controls that you write, doit is always false.
Table 2.11. The doit and detail Fields
doit???????????????? detail?????????????????????? Traversal Performed????????? Key Event
?
true?????????????? Don't assign???????????????????????? Yes?????????????????????????????? No
?
false???????????? Don't assign?????????????????????????? No?????????????????????????????? Yes
?
true???????????? SWT.TRAVERSE_NONE??????????? No??????????????????????? No
?
false??????????? SWT.TRAVERSE_NONE??????????? No??????????????????????? Yes
?
Accelerator
item.setText("Select &All\tCtrl+A");
item.setAccelerator(SWT.MOD1 + 'A');
item.addListener(SWT.Selection, new Listener() {
??? public void handleEvent(Event e) {
??????? System.out.println("The item was selected.");
??? }
});
?
?
?
?
?
?
?
?