0 Replies Latest reply: Mar 15, 2013 9:06 AM by 997166 RSS

    JavaFX - SWT interoperation: application freezes

    997166
      Hello,

      I am building a RCP application, based on Eclipse 3.5. Thanks to two articles[1][2] that I've found on oracle.com, I have been able to implement a working RCP view, that displays a pie chart.

      Unfortunately, if I close the view and reopen it, then the applications freezes and never comes back.

      I am using JavaFX 2.2.7, under JDK 1.6.0.31 on Windows 7 X64.

      Here is the code. The view is a standard subclass of org.eclipse.ui.part.ViewPart.

      Composite panel = new Composite(parent, SWT.NONE);
      RowLayout layout = new RowLayout();
      panel.setLayout(layout);
      FXCanvas fxCanvas = new FXCanvas(panel, SWT.NONE) {
      @Override
      public Point computeSize(int wHint, int hHint, boolean changed) {
      getScene().getWindow().sizeToScene();
      int width = (int) getScene().getWidth();
      int height = (int) getScene().getHeight();
      return new Point(width, height);
      }
      };

      Scene scene = new Scene(new Group());
      RGB rgb = panel.getBackground().getRGB();
      Color color = Color.rgb(rgb.red, rgb.green, rgb.blue);
      scene.setFill(color);
      ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList();
      pieChartData.add(new PieChart.Data("label1", 20));
      pieChartData.add(new PieChart.Data("label2", 20));
      pieChartData.add(new PieChart.Data("label3", 20));
      pieChartData.add(new PieChart.Data("label4", 20));
      pieChartData.add(new PieChart.Data("label5", 20));
      Chart chart = new PieChart(pieChartData);
      chart.setLegendSide(Side.RIGHT);
      ((Group) scene.getRoot()).getChildren().add(chart);
      fxCanvas.setScene(scene);

      Can anyone help?


      [1]http://docs.oracle.com/javafx/2/swt_interoperability/jfxpub-swt_interoperability.htm
      [2]http://docs.oracle.com/javafx/2/charts/pie-chart.htm#CIHFDADD