简体   繁体   English

如何在Eclipse RCP应用程序中更改首选项页面的标题?

[英]How to change title of preference page in eclipse RCP application?

如何在Eclipse RCP中将首选项页面的默认title从“首选项”更改为“设置”?

If you are using the org.eclipse.ui.preferencePages then I think it is not possible. 如果您使用的是org.eclipse.ui.preferencePages那么我认为这是不可能的。 The help of the same says: 相同的帮助说:

The workbench provides one common dialog box for preferences. 工作台为首选项提供了一个通用对话框。 The purpose of this extension point is to allow plug-ins to add pages to the preference dialog box . 此扩展点的目的是允许插件将页面添加首选项对话框 When preference dialog box is opened (initiated from the menu bar), pages contributed in this way will be added to the dialog box. 当打开首选项对话框(从菜单栏启动)时,以这种方式贡献的页面将被添加到对话框中。

But there is a way round. 但是有办法解决。 Follow the below steps ( This is just showing how you can change the title text ): 请按照以下步骤操作( 这只是显示如何更改标题文本 ):

  1. Create an action for opening the preference dialog 创建一个操作以打开首选项对话框
  2. Make a new class extending the org.eclipse.jface.preference.PreferenceDialog 新建一个扩展org.eclipse.jface.preference.PreferenceDialog
  3. In the sub-class override the configureShell method 在子类中重写configureShell方法
  4. Invoke the PreferenceDialog from the above created action 从上面创建的操作中调用PreferenceDialog

Extended Class

class MyPreferenceDialog extends PreferenceDialog
{
    public MyPreferenceDialog(Shell parentShell, PreferenceManager manager) {
        super(parentShell, manager);
    }

    protected void configureShell(Shell newShell) {
        super.configureShell(newShell);
        newShell.setText("Settings"); 
    }
}

Code For Invocation

Button prefButton = new Button(top, SWT.PUSH);
prefButton.setText("Preference");
prefButton.addSelectionListener(new SelectionListener() {
    public void widgetSelected(SelectionEvent e) {
        final PreferenceManager preferenceManager = PlatformUI.getWorkbench().getPreferenceManager();
        MyPreferenceDialog dialog = new MyPreferenceDialog(top.getShell(), preferenceManager);
        dialog.create();
        dialog.open();
    }
    public void widgetDefaultSelected(SelectionEvent e) {
    }
});

The resultant preference dialog looks like this: 结果首选项对话框如下所示:

在此处输入图片说明

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

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