简体   繁体   English

RCP SWT Eclipse-清除复合容器

[英]RCP SWT Eclipse - Clear a composite container

I need your help... I have a 2 Composite container. 我需要您的帮助...我有一个2复合容器。 One of them with 2 radio button, the first radio button is CHART and the other is REPORT. 其中一个带有2个单选按钮,第一个单选按钮是CHART,另一个是REPORT。 When the user select chart, a chart is loaded in the second Composite, everything ok but I don´t know how to remove the chart when the user select "report", is there any way to clear or remove it? 当用户选择图表时,将图表加载到第二个Composite中,一切正常,但是当用户选择“报告”时我不知道如何删除图表,有什么方法可以清除或删除它? I tried it but I can´t find a solution. 我尝试过,但是找不到解决方案。 Thanks! 谢谢!

contenedor_chart = new Composite(parent, SWT.NONE);
        contenedor_chart.setLayout(new FillLayout());
        FillLayout filllayout = new FillLayout();
        filllayout.marginWidth = 50;
        filllayout.marginHeight = 50;

        contenedor_chart.setLayout(filllayout);
        CategoryDataset dataset = cbch.createDataset();
        JFreeChart chart = cbch.createChart(dataset);
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(400, 170));
        new ChartComposite(contenedor_chart, SWT.NONE, chart, true);

You can just dispose of the control you no longer want by calling its dispose method: 您可以通过调用其dispose方法来dispose不再需要的控件:

Control chart = ... chart control

chart.dispose();

Just calling dispose will not reclaim the space used by the control unless you force the controls to be layed out again. 仅调用dispose不会回收控件使用的空间,除非您强制重新dispose控件。 For example to lay out the whole Shell use: 例如,对整个Shell进行布局:

Shell shell = ... current shell

shell.pack();

which lays out the controls in the shell and adjusts the shell size to fit. 它在外壳中布置控件并调整外壳大小以适合。

If you want to reuse the chart then don't call dispose or pack . 如果要重用图表,请不要调用disposepack You can just call setVisible(false) on the control. 您可以仅在控件上调用setVisible(false)

You could also look at using StackLayout to layout multiple controls in a Composite or use the Eclipse PageBook control. 您还可以查看使用StackLayoutComposite布局多个控件或使用Eclipse PageBook控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM