带有Eclipse Look的Eclipse RCP工具栏按钮

在Eclipse中,使用ActionSets扩展点可以轻松指定工具栏的按钮。 但是,当我需要以编程方式指定一些项目时,我无法获得相同的外观。 我不相信框架使用本机按钮,但到目前为止,我找不到与Eclipse外观相匹配的正确配方。 我想看看是否有人找到了在代码中复制此function的正确代码段。

从您的问题中很难说出来,但听起来您可能正在尝试将ControlContribution添加到工具栏并返回Button。 这将使工具栏上的按钮看起来像您似乎在描述的本机按钮。 这看起来像这样:

IToolBarManager toolBarManager = actionBars.getToolBarManager(); toolBarManager.add(new ControlContribution("Toggle Chart") { @Override protected Control createControl(Composite parent) { Button button = new Button(parent, SWT.PUSH); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { // Perform action } }); } }); 

相反,您应该将Action添加到工具栏。 这将在工具栏上创建一个与标准eclipse工具栏按钮匹配的按钮。 这看起来像这样:

 Action myAction = new Action("", imageDesc) { @Override public void run() { // Perform action } }; IToolBarManager toolBarManager = actionBars.getToolBarManager(); toolBarManager.add(myAction); 

您是否可以将用于以编程方式添加操作的代码提取到工具栏中? 我假设您在ApplicationActionBarAdvisor类中执行此操作? 它们与你以编程方式添加的按钮的外观相比应该没有区别。