swt窗口范围内的LostFocus事件的实现Java认证考试
文章作者 100test 发表时间 2010:02:18 22:12:06
来源 100Test.Com百考试题网
SWT中如果添加一个Lost Focus事件后,会发现当窗体切换、最小化窗体等事件发生的时候都会激发Lost Focus事件,这显然不过友善。传统意义上的Lost Focus事件应该是只有焦点迁移到单前窗体中的某个空间的时候才需要激发Lost Focus事件。但是由于RCP程序中,一个窗体可能包含多个View和Editor,所以这个Listener实现了当焦点迁移到指定 Composite中时,激发LostFocus事件。
事件代码
使用方式
1、监听指定容器的Lost Focus事件
// 监听指定容器的Lost Focus事件
DCFocusLostListener listenter = new DCFocusLostListener(cmpParent, m_Control) {
public void dcFocusLost(FocusEvent event) {
// TODO 业务处理
}
}.
// 如果控件已经取得了焦点,就需要手工调用registerFilter()
listenter.registerFilter().
2、监听窗体的Lost Focus事件
// 监听窗体的Lost Focus事件
DCFocusLostListener listenter = new DCFocusLostListener(shell, m_Control) {
public void dcFocusLost(FocusEvent event) {
// TODO 业务处理
}
}.
package study.swt.event.
import org.eclipse.swt.SWT.
import org.eclipse.swt.events.FocusEvent.
import org.eclipse.swt.events.FocusListener.
import org.eclipse.swt.widgets.Composite.
import org.eclipse.swt.widgets.Control.
import org.eclipse.swt.widgets.Event.
import org.eclipse.swt.widgets.Listener.
/**
*