Hi
I have been trying to get a jme3 canvas inside a javafx window using SwingNode from JavaFX8 as a test before proceeding with an application.
The problem I have at the moment is that the canvas is not displaying, but the other swing object (a button) is and working fine. To be more correct there is a blank space where the canvas would be, and the swing button to the right as it is in the SwingCanvasTest
Does any one have an idea of what I am doing to make this fail?
I have this code based on a swing canvas example,
[java]
public class Jme3fx extends SimpleApplication {
public static JPanel panel = new JPanel(new FlowLayout());
@Override
public void simpleInitApp() {
// activate windowed input behaviour
flyCam.setDragToRotate(true);
// display a cube
Box boxshape1 = new Box(new Vector3f(-3f, 1.1f, 0f), 1f, 1f, 1f);
Geometry cube = new Geometry("My Textured Box", boxshape1);
Material mat_stl = new Material(assetManager, "Common/MatDefs/Misc/ColoredTextured.j3md");
Texture tex_ml = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
mat_stl.setColor("Color", ColorRGBA.Blue);
cube.setMaterial(mat_stl);
rootNode.attachChild(cube);
}
public void makeitgo() {
//panel = new JPanel(new FlowLayout()); // a panel
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
// create new JME appsettings
AppSettings settings = new AppSettings(true);
settings.setWidth(640);
settings.setHeight(480);
// create new canvas application
Jme3fx canvasApplication = new Jme3fx();
canvasApplication.setSettings(settings);
canvasApplication.createCanvas(); // create canvas!
JmeCanvasContext ctx = (JmeCanvasContext) canvasApplication.getContext();
ctx.setSystemListener(canvasApplication);
Dimension dim = new Dimension(640, 480);
ctx.getCanvas().setPreferredSize(dim);
panel.add(ctx.getCanvas()); // add JME canvas
canvasApplication.startCanvas();
}
});
//return panel;
}
/**
* @return
*/
public JComponent getPanel() {
// TODO Auto-generated method stub
JButton button = new JButton("Swing Component");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
//Execute when button is pressed
System.out.println("You clicked the button");
}
});
panel.add(button);
return panel;
}
}
[/java]
and this code to display it in a FX window
[java]
jmeapp = new Jme3fx();
jmeapp.makeitgo();
createAndSetSwingContent();
jmepane.getChildren().add(swingNode);
private void createAndSetSwingContent() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
swingNode.setContent(jmeapp.getPanel());
}
});
}
[/java]