Hi !
(I hope I am in the right cathegory, and sorry for my english, I’m french. )
After some research on the web, and on the forum.
I want to know if it’s possible to embed JME into a JavaFX Pane ? Or if a feature is planned for the project ?
I’ve found some codes and trying to integrate my jme render inside a JPanel and inside a SwingNode.
But nothing seems to works, (old posts)
I haven’t any render.
I share with you my actual work:
Code Main Class
`public class Main extends Application {
private FXMLLoader loader;
private Stage primaryStage;
private AnchorPane root;
private MineImationApp mineImationApp = new MineImationApp();
private MineImation mineImation = new MineImation();
@Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
this.primaryStage.setTitle("MineImation");
try {
this.mineImation.preInit(mineImationApp, loader, primaryStage);
this.initializeOverview();
this.mineImation.postInit(mineImationApp, loader, primaryStage);
Scene scene = new Scene(this.root);
this.primaryStage.setScene(scene);
this.primaryStage.show();
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* Shows the person overview inside the root layout.
*/
private void initializeOverview() {
try {
this.loader = new FXMLLoader();
this.loader.setLocation(Main.class.getResource("/MineImationOverview.fxml"));
this.root = (AnchorPane) this.loader.load();
}
catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}`
Code MineImation Class
`public class MineImation implements IApplication {
private JPanel renderPanel = new JPanel();
@Override
public void preInit(MineImationApp appIn, FXMLLoader loader, Stage primaryStage) {
renderPanel.setBackground(Color.DARK_GRAY);
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
public void handle(WindowEvent e) {
appIn.stop(true);
}
});
primaryStage.setOnHidden(new EventHandler<WindowEvent>() {
public void handle(WindowEvent e) {
appIn.enqueue(new Function<SimpleApplication, Boolean>() {
public Boolean apply(SimpleApplication t) {
t.loseFocus();
return Boolean.valueOf(true);
}
});
}
});
primaryStage.setOnShowing(new EventHandler<WindowEvent>() {
public void handle(WindowEvent e) {
appIn.enqueue(new Function<SimpleApplication, Boolean>() {
public Boolean apply(SimpleApplication t) {
t.gainFocus();
return Boolean.valueOf(true);
}
});
}
});
appIn.enqueue(new Function<SimpleApplication, Boolean>() {
public Boolean apply(SimpleApplication t) {
t.getStateManager().attach(new AppStateMain());
t.getStateManager().attach(new ModifiedFlyCamAppState());
t.getStateManager().attach(new ScreenshotAppState(OSHelper.getWorkingDirectory() + "/screenshots/", "mineimation-"));
JmeCanvasContext ctx = (JmeCanvasContext) appIn.getContext();
ctx.setSystemListener(appIn);
renderPanel.add(ctx.getCanvas());
return true;
}
});
}
@Override
public void init(MineImationApp appIn, FXMLLoader loader, Stage primaryStage) {}
@Override
public void postInit(MineImationApp appIn, FXMLLoader loader, Stage primaryStage) {
final SwingNode swingNode = new SwingNode();
BorderPane borderPane = (BorderPane) getComponent(loader, "borderPane_modelBuilder");
swingNode.setContent(this.renderPanel);
borderPane.setCenter(swingNode);
}
public Object getComponent(FXMLLoader loader, String keyIn) {
return loader.getNamespace().get(keyIn);
}
}`
The IApplication interface if for preInit(), init() an postInit() states.
So, I don’t know if I made a bad code or if it’s just JME who doesn’t support JavaFX.
Thanks for help by advance !