I finally got more of a handle on how the Canvas implementations work. So now I'm trying to embed into Swing but without much success.
Here's the code...
package jzy3d.example;
import java.awt.Canvas;
import java.awt.Panel;
import javax.swing.JFrame;
import javax.swing.JPanel;
import junit.framework.TestCase;
import org.jzy3d.chart.Chart;
import org.jzy3d.colors.Color;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.plot3d.primitives.Scatter;
public class Cloud3DTest extends TestCase {
public static void plot(String canvasType) {
// Create a test chart.
int size = 100000;
Coord3d[] points = new Coord3d[size];
for (int i=0; i<size; i++) {
points[i] = new Coord3d(
(float) Math.random() - 0.5f,
(float) Math.random() - 0.5f,
(float) Math.random() - 0.5f);
}
Scatter scatter = new Scatter(points);
scatter.setColor(Color.BLUE);
Chart chart = new Chart(canvasType);
chart.getAxeLayout().setMainColor(Color.WHITE);
chart.getView().setBackgroundColor(Color.BLACK);
chart.getScene().add(scatter);
// Embed into Swing.
JFrame frame = new JFrame();
JPanel panel = new JPanel();
panel.setOpaque(false);
if (chart.getCanvas() instanceof Canvas) {
panel.add((Canvas) chart.getCanvas());
} else if (chart.getCanvas() instanceof Panel) {
panel.add((Panel) chart.getCanvas());
}
frame.setContentPane(panel);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setTitle(canvasType);
frame.setVisible(true);
}
public static void main(String args[]) {
plot("swing");
plot("newt");
plot("awt");
}
}
None of the three canvas types show anything. In fact, the parent JPanel is quite tiny so it isn't even sized correctly.
Am I doing something dumb? Or missing something obvious here? Probably both...