简体   繁体   English

如何改变对JFace WizardPage按钮的关注?

[英]How do I change the focus on buttons of JFace WizardPage?

I have implemented a JFace Wizard with 2 WizardPages. 我已经实现了带有2个WizardPages的JFace向导。

By default, the first WizardPage has these 4 Buttons: 默认情况下,第一个WizardPage具有以下4个按钮:

  • Back (disabled) 返回(已禁用)
  • Next (focused) 下一步(重点)
  • Cancel 取消
  • Finish (disabled) 完成(禁用)

Now I want to set the default focus on the Cancel Button. 现在,我要在“取消”按钮上设置默认焦点。 How do I do that? 我怎么做?

Removing the focus and setting it to some Control of the page's content would also be ok. 移除焦点并将其设置为对页面内容的某种控制也是可以的。

I tried setting the focus to a Button in the content layout of the WizardPage, but this only sets me a second focus on the immediateButton . 我试图在WizardPage的内容布局中将焦点设置为Button,但这仅将我的第二个焦点放在了immediateButton The focus on the Next button is still there, and the Next button reacts to pressing enter, which is what I want to avoid. 仍将焦点放在“下一步”按钮上,并且“下一步”按钮会对按下Enter做出反应,这是我要避免的事情。

@Override
public void setVisible(boolean visible) {
    super.setVisible(visible);
    if (visible) {
        immediateButton.setFocus();
    }
}

How can I access the Dialog buttons and change their focus? 如何访问对话框按钮并更改其焦点?

The Next button does not actually have focus, rather it is the Shell Default button. Next按钮实际上没有焦点,而是Shell默认按钮。

The logic in WizardDialog makes either Next or Finish the default button and there does not seem to be a way to change this. WizardDialog的逻辑将“下一步”或“完成”设置为默认按钮,并且似乎没有办法更改此按钮。

You may be able to override this by calling getShell().setDefaultButton(button) in your wizard page. 您可以通过在向导页面中调用getShell().setDefaultButton(button)来覆盖它。

Update: Testing this you can do it in setVisible but you need to use Display.asyncExec to make the code run at the right time: 更新:测试此操作可以在setVisible但是您需要使用Display.asyncExec使代码在正确的时间运行:

final Shell shell = getShell();

shell.getDisplay().asyncExec(() -> shell.setDefaultButton(immediateButton));

above is for Java 8, for Java 7 or earlier: 以上适用于Java 8,适用于Java 7或更早版本:

shell.getDisplay().asyncExec(new Runnable()
   {
     @Override
     public void run()
     {
       shell.setDefaultButton(immediateButton); 
     }
   });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM