Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] Problem with mouse on SWT_AWT

Hi all,


I'm trying to use the SWT_AWT library and I integrated some JFreeChart (a nice open source chart drawing component) chart in my application. This works I can see my charts in SWT embedded composite, but I have a little problem with mouse events. JFreeChart allows to zoom/unzoom charts by drawing a rectangle with mouse, but I can't do it in the embedded composite.
Does somebody have an idea on how I could get jfreechart mouse events working? Maybe I have to connect SWT events to AWT event? A problem of focus?
Thanks for help.

Mathieu.

PS : Here is a snippet of the way I integrated JFreeChart on SWT :


public ScatterPlotView(Composite parent, int style) {
        super(parent, style);
       
        GridLayout layout = new GridLayout(1, true);
        layout.verticalSpacing = 0;
        layout.horizontalSpacing = 0;
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        setLayout(layout);
       
        Composite jFreeComp = new Composite(this, SWT.EMBEDDED);
        jFreeComp.setLayoutData(new GridData(GridData.FILL_VERTICAL | GridData.FILL_HORIZONTAL));
       
        java.awt.Frame jfreeFrame = SWT_AWT.new_Frame(jFreeComp);
       
        XYDataset data = "" SampleXYDataset2();
        JFreeChart chart = ChartFactory.createScatterPlot(
            "Scatter Plot",
            "X", "Y",
            data,
            PlotOrientation.VERTICAL,
            true,
            true,
            false
        );
        Legend legend = chart.getLegend();
        if (legend instanceof StandardLegend) {
            StandardLegend sl = (StandardLegend) legend;
            sl.setDisplaySeriesShapes(true);
        }
        NumberAxis domainAxis = (NumberAxis) chart.getXYPlot().getDomainAxis();
        domainAxis.setAutoRangeIncludesZero(false);
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        chartPanel.setVerticalAxisTrace(true);
        chartPanel.setHorizontalAxisTrace(true);
        chartPanel.setVerticalZoom(true);
        chartPanel.setHorizontalZoom(true);
        chartPanel.setAutoscrolls(true);
        chartPanel.setMouseZoomable(true);
       
        jfreeFrame.add(chartPanel);
}

Back to the top