将按钮添加到RCP应用程序(Adding a button to a RCP application)

编程入门 行业动态 更新时间:2024-10-10 00:20:54
将按钮添加到RCP应用程序(Adding a button to a RCP application)

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

当我添加行:panel.add(按钮); 它返回一个错误:类型Container中的方法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); } });

I want to add a button to a RCP client. The window needs to display my barChart as well as 3 buttons.

When i add the line: panel.add(button); it returns an error: The method add(Component) in the type Container is not applicable for the arguments (Button)

Please help :)

@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); } });

最满意答案

不使用Panel ,而是使用Composite 。 Panel来自Swing ,你将Swing与RCP / SWT混合,这是不明智的。

你正在使用的Button来自SWT,你将它添加到Panel ,它是一个Swing组件,你只能将一个Swing组件添加到Panel 。 您可以将Button更改为AWT的Button或Swing的JButton 。 否则如前所述,将Panel更改为Composite 。

Instead of using a Panel, use Composite. Panel is from Swing and you are mixing Swing with RCP/SWT, which is not wise.

The Button that you are using is from SWT and you are adding that to Panel which is a Swing component and you can only a Swing component to Panel. You can either change the Button to AWT's Button or Swings JButton. Otherwise as stated earlier, change the Panel to Composite.

更多推荐

本文发布于:2023-07-06 07:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047303.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   按钮   RCP   application   Adding

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!