我正在开发一个Eclipse RCP应用程序。在一个扩展MultiPageEditorPart的类中,我尝试将焦点设置为文本字段。但是setFocus方法总是返回false。
我做错了什么?
MultiPageEditor有不同的页面,在这些页面中,有一些复合类。这些类包含文本字段。
下面是代码片段:(errorPage是一个整数,我的验证在其上发现错误的页码)
if(!dataValid) {
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Fehler bei der Dateneingabe", stringBuilder.toString());
this.setActivePage(errorPage);
Composite errorComposite = (Composite) this.getControl(errorPage);
Control[] children = errorComposite.getChildren();
for (Control child : children) {
if(child instanceof Form) {
Form form = (Form) child;
Composite body = form.getBody();
Control[] formChildren = body.getChildren();
for (Control formChild : formChildren) {
if(formChild.equals(errorControl))
formChild.setFocus();
return dataValid;
}
}
}
}
发布于 2010-01-28 10:03:45
在以下情况下,setFocus()可能会返回false:
因此,我最好检查一下,(1)我是否将焦点设置在正确的控件上,(2)控件是否可见,可能包含该控件的窗体不在当前选定的选项卡中。(3)是否打开了任何其他模式对话框。
发布于 2010-01-28 07:20:54
你试过Control#forceFocus()吗?
https://stackoverflow.com/questions/2148143
复制相似问题