将一个键侦听器添加到TitleAreaDialog [英] Add a Key Listener to TitleAreaDialog
本文介绍了将一个键侦听器添加到TitleAreaDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在我的TitelAreaDialog
中添加一个键侦听器,有什么解决方案吗?
I need to add a key listener to my TitelAreaDialog
is there any solution to do this ?
推荐答案
您可以使用以下方法将Listener
添加到Display
:
You can add a Listener
to the Display
by using:
Listener listener = new Listener() {
public void handleEvent(Event event) {
System.out.println(event.character);
}
}
getShell().getDisplay().addFilter(SWT.KeyDown, listener);
这将在不占用事件的情况下输出所有按下的键,即基础窗口小部件仍将注册事件.
This will output all pressed keys without consuming the events, i.e. the underlying widgets will still register the events.
请记住在Dialog
的close()
方法中再次将其删除:
Remember to remove it again in the close()
method of the Dialog
:
@Override
public boolean close()
{
getShell().getDisplay().removeFilter(SWT.KeyDown, listener);
super.close();
}
这篇关于将一个键侦听器添加到TitleAreaDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文