Add a Key Listener to TitleAreaDialog

余生长醉 提交于 2019-12-25 02:58:51

问题


I need to add a key listener to my TitelAreaDialog is there any solution to do this ?


回答1:


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.


Remember to remove it again in the close() method of the Dialog:

@Override
public boolean close()
{
    getShell().getDisplay().removeFilter(SWT.KeyDown, listener);
    super.close();
}


来源:https://stackoverflow.com/questions/12752468/add-a-key-listener-to-titleareadialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!