java - How to perform Key Listener on SWT Label -
keylistener not performed on label. please one? below code snippet:
breaknodelabel = new label(this, swt.wrap); breaknodelabel.setbackground(new color(getdisplay(), 204, 204, 204)); breaknodelabel.addkeylistener(new keyadapter() { @override public void keypressed(keyevent event) { if (event.keycode == swt.del) { // deletenode(this); system.out.println("------------delete break node----------------"); } } });
you've added keylistener label. label must have focus events.
if want listen keyboard events in whole window add keylistener shell:
shell.addkeylistener(new keyadapter()...
if want global keylistener add display filter:
listener listener = new listener() { @override public void handleevent(event e) { if(e.type == swt.keydown||e.type == swt.keyup) { system.out.println("" + e.keycode); } } }; display.addfilter(swt.keydown, listener); display.addfilter(swt.keyup, listener);
Comments
Post a Comment