【发布时间】:2020-09-16 05:22:40
【问题描述】:
我正在开发一个 Eclipse RCP 应用程序。我有一个从 IWorkbenchPreferencePage 继承的首选项页面。在首选项页面中,我有一个按钮,单击该按钮会生成一个外壳。 shell 始终处于失焦状态,并且在设置首选项页面之前无法与之交互。
有什么方法可以将焦点设置在shell上?
这里是一些偏好页面的伪代码:
public class PreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
AuthenticationManager authenticationManager = new AuthenticationManager();
@Override
protected void createFieldEditors() {
final Button login = new Button(getFieldEditorParent(), SWT.PUSH);
login.setText("Login")
login.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(final SelectionEvent se) {
authenticationManager.run(getShell().getDisplay());
}
}
}
}
public AuthenticationManager {
public void run(@Nullable Display optionalDisplay) {
display.asyncExec(() -> {
// set the url & add listeners
}
}
}
谢谢!
【问题讨论】:
-
你是如何创建外壳的? shell 的父级是什么?首选项对话框是应用程序模式,只有以对话框为父级的 shell 才能获得焦点。
-
如果你想继续这个问题,你需要回答我之前评论中的问题。
标签: java eclipse eclipse-rcp