我想向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.
更多推荐
发布评论