Is anyone successfully using JFreechart on a Mac (Mavericks) using Java 8 (1.8.0_05) - in a JavaFX SwingNode? I have submitted a java bug report for a hang in CGLGraphicsConfig.getMaxTextureSize which seems to happen for even the most trivial of Jfreecharts. I have enclosed the code below to reproduce. I'm just wondering whether anyone has come across, and found a fix/workaround? The bug itself (or something really similar) seems to have featured before but was closed a few times in jdk 7. I can't use jdk 7 though. I adapted the same chart from one of the demos, and made it really minimal.
This all works fine on a PC by the way, and apart from sizing issues have not had any problems with JfreeChart inside a SwingNode on a PC.
Thanks!
Code: Select all
package demo;
import javafx.application.Application;
import javafx.embed.swing.SwingNode;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javax.swing.SwingUtilities;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
public class AwtBugDemonstrator extends Application {
@Override
public void start(Stage primaryStage) {
try {
primaryStage.setTitle("Awt Bug Demonstrator");
BorderPane bp = new BorderPane();
Scene scene = new Scene(bp, 400, 400);
SwingNode sn = new SwingNode();
ChartPanel c = new ChartSample().getPanel();
try {
SwingUtilities.invokeAndWait(
()->{
// hangs inside here...
sn.setContent(c);
}
);
} catch (Exception ex) {
ex.printStackTrace();
}
bp.setCenter(sn);
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
//public class LineChartDemo6 extends ApplicationFrame {
public class ChartSample {
ChartPanel chartPanel;
public ChartSample() {
final XYDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(400, 400));
}
public ChartPanel getPanel() {
return chartPanel;
}
private XYDataset createDataset() {
final XYSeries series1 = new XYSeries("First");
series1.add(1.0, 1.0);
final XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series1);
return dataset;
}
private JFreeChart createChart(final XYDataset dataset) {
final JFreeChart chart = ChartFactory.createXYLineChart(
"Bug Demonstrator", "X", "Y", dataset,
PlotOrientation.VERTICAL,true, true, false
);
final XYPlot plot = chart.getXYPlot();
final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
plot.setRenderer(renderer);
return chart;
}
}
}