【发布时间】:2013-06-10 19:26:41
【问题描述】:
我想向 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);
}
});
【问题讨论】:
-
是
java.awt.Button吗?如果是则button.setText("Press");应该抛出编译错误。 -
导入 org.eclipse.swt.widgets.Button; :) 删除 setText 对我得到的错误没有任何影响