So I’d been trying to figure out why I couldn’t get a Xith3D window to fit into a lightweight control, specifically a Swing JInternalFrame and now I know why.
public CanvasPeer makeCanvas(Object owner, int width, int height, int bits,
boolean fullScreen, GLCapabilities gc) {
Frame frame = null;
CanvasPeerImpl c = new CanvasPeerImpl(this, owner, width, height, bits, fullScreen, gc);
if (owner == null) {
frame = new Frame("Xith3d");
frame.setSize(width, height);
if (fullScreen) frame.setUndecorated(true);
c.setWindow(frame);
frame.add(c.getComponent());
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.show();
} else {
Component comp = c.getComponent();
comp.setBounds(0,0,width,height);
((Container)owner).add(comp);
}
//GLCanvas canvas = (GLCanvas) c.getComponent();
return c;
}
When this is used in conjunction with the stuff in the tutorials:
CanvasPeer cp = rp.makeCanvas(null, 640, 480, 32, false);
What you end up with is not the CanvasPeerImpl, but instead a Frame which contains the CanvasPeerImpl. Now with that said, if I wanted to ‘getContentPane().add()’ this Canvas3D to a container object - would I have to pass in the component that I want this to be a child of - that seems to be the case here.
JFrame myJFrame = new JFrame("foo");
...
CanvasPeer cp = rp.makeCanvas(myJFrame, 640, 480, 32, false);
I have a feeling that this would fail because of
((Container)owner).add(comp);