0

我想向 RCP 客户端添加一个按钮。该窗口需要显示我的条形图以及 3 个按钮。

当我添加行时: panel.add(button); 它返回错误:容器类型中的方法 add(Component) 不适用于参数 (Button)

请帮忙 :)

@Override
    protected void createWindows(final Shell shell) throws Exception {
        shell.setLayout(new FillLayout());
        final Composite composite = new Composite(shell, SWT.EMBEDDED);

        final Frame frame = SWT_AWT.new_Frame(composite); 
        final StaticBarSketch barGraph = new StaticBarSketch();
        final Button button = new Button(composite, SWT.PUSH);
        button.setText("Press");

        Panel panel = new Panel();
        panel.add(barGraph);
        frame.add(panel);
        barGraph.init();

        composite.addListener(SWT.Resize, new Listener() {
            @Override
            public void handleEvent(Event event) {
                barGraph.resized(composite.getSize().x, composite.getSize().y);
            }
        });
4

1 回答 1

0

而不是使用 a Panel,使用Composite. Panel来自Swing并且您正在Swing与 RCP/SWT 混合,这是不明智的。

您正在使用的Button来自 SWT,并且您正在向Panel其中添加一个Swing组件,并且您只能将一个Swing组件添加到Panel. 您可以更改ButtonAWT'sButtonSwings JButton。否则如前所述,将 更改PanelComposite

于 2013-06-14T08:17:13.733 回答