将一个键侦听器添加到TitleAreaDialog [英] Add a Key Listener to TitleAreaDialog

查看:86
本文介绍了将一个键侦听器添加到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.

请记住在Dialogclose()方法中再次将其删除:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆