Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将工具栏添加到节_Java_Eclipse_Eclipse Plugin_Swt - Fatal编程技术网

Java 将工具栏添加到节

Java 将工具栏添加到节,java,eclipse,eclipse-plugin,swt,Java,Eclipse,Eclipse Plugin,Swt,我想在SWT中的一个部分添加一个工具栏。 我在PDE清单编辑器中看到了一个示例 如何添加此工具栏或按钮? 也许我需要使用不同的控件 谢谢,, Ido您可以使用ImageHyperLink控件。我认为这就是PDE清单编辑器所使用的 Section section = new Section(parent, SWT.NONE); Composite toolbar = new Composite(section, SWT.NONE); RowLayout layout = new RowLayout

我想在SWT中的一个部分添加一个工具栏。 我在PDE清单编辑器中看到了一个示例

如何添加此工具栏或按钮? 也许我需要使用不同的控件

谢谢,,
Ido

您可以使用ImageHyperLink控件。我认为这就是PDE清单编辑器所使用的

Section section = new Section(parent, SWT.NONE);
Composite toolbar = new Composite(section, SWT.NONE);
RowLayout layout = new RowLayout(SWT.HORIZONTAL);
layout.marginLeft = 0;
layout.marginRight = 0;
layout.spacing = 0;
layout.marginTop = 0;
layout.marginBottom = 0;
toolbar.setLayout(layout);
parent.setTextClient(toolbar);

ImageHyperlink imageHyperLink = new ImageHyperlink(toolbar, SWT.CENTER);
imageHyperLink.setBackgroundImage(section.getBackgroundImage());
imageHyperLink.setToolTipText("Click me for help");
imageHyperLink.setImage(JFaceResources.getImage(Dialog.DLG_IMG_HELP));
imageHyperLink.addHyperlinkListener(new HyperlinkAdapter()
{
    public void linkActivated(HyperlinkEvent e)
    {
         // Show help
    }
});

由于发布的解决方案没有生成透明的背景图标,我研究了如何获得与插件清单编辑器的扩展页面相同的结果

以下是他们创建工具栏的方式:

    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    ToolBar toolbar = toolBarManager.createControl(section);
    toolbar.setCursor(Display.getDefault().getSystemCursor(SWT.CURSOR_HAND));

    // Add sort action to the tool bar
    fSortAction = new SortAction(fExtensionTree, PDEUIMessages.ExtensionsPage_sortAlpha, null, null, this);
    toolBarManager.add(fSortAction);
    // Add collapse action to the tool bar
    fCollapseAction = new CollapseAction(fExtensionTree, PDEUIMessages.ExtensionsPage_collapseAll);
    toolBarManager.add(fCollapseAction);

    toolBarManager.update(true);

    section.setTextClient(toolbar);
编辑:

这似乎也很有效:

ToolBar toolbar = new ToolBar(section, SWT.NONE);
//add the toolitems here
//...
section.setTextClient(toolbar);

不要让Window Builder工具使用
FormToolkit
调整工具栏,否则您将得到白色背景。

您能解释一下“部分”吗?或者你在哪里找到了这个例子?看看这篇文章: