JavaFX SwingNode does not appear
Hi, I am developing a plugin that launches a JavaFX application in which there is an SwingNode object. When I run the application, it works, but when I run the plugin, is not showing anything, just an empty window. The code I try is very simple:
public void start(Stage stage) {
final SwingNode swingNode = new SwingNode();
swingNode.setContent( new JButton( "paquee" ) );
StackPane pane = new StackPane();
pane.getChildren().add(swingNode);
stage.setTitle("Swing in JavaFX");
stage.setScene(new Scene(pane, 250, 150));
stage.show();
}
How could I make it work? Thank you!!!!!
Please sign in to leave a comment.
SwingNode should be used to embed a Swing content into a JavaFX application per its javadoc. when you run plugin in IDEA, you first have swing application and then JavaFX. I guess you need javafx.embed.swing.JFXPanel instead.
Hi Anna, thanks!
when you say instead...instead of what?? Actually, what I am setting on the SwingNode object is an object from a class that extends JComponent. -> swingNode.setContent(x) ,, where x is an object from a class that extends JComponent.
IDEA is a swing application, so you need to integrate your javafx application into swing application. JFXPanel was created for this purpose.
Okey, so if I understand well, you advise me to create a Swing application , integrating my javafx application into the swing, and inside this javafx the SwingNode?, because I need it to be in an area (pane) that is in the javafx,,, something like: Swing(javafx(swingnode)) ??
IDEA plugin is already integrated into Swing application. You need to integrate your javaFX application inside it or don't use javafx in IDEA plugin.
I already set it like I said in last comment and is working! thank you very much again!
Hi Anna, I finished the plugin using JFXPanel as you said, and once I try to run it on Android Studio, it gives me this errors:
Plugin Error: NoClassDefFoundError: javafx/embed/swing/JFXPanel,
Do you know how can I solve it? Thank you!
Please check if JDK on which AndroidStudio runs, contains jfxrt jar. If not, please ask on their support forum for the reasons, I am not aware of versions of JDK they use, sorry. Probably they will update soon to our JDK and the problem goes away by itself