How to insert JPanel into JavaFX panel?

How to add swingNode panel to specific ?

I'm actually trying to add a JPanel that loads the applet into the transparent area below, and I'm not sure how to do it.

enter image description here

+7
java swing javafx jpanel
source share
1 answer

SwingNode is a javafx scene node and can be added to any javafx layout .

To add a JPanel to a panel and display it in the JavaFX step:

  • Add JPanel to SwingNode
  • Assign the swingnode as a child of any of the layouts (including the panel).
  • Set the layout as the scene root
  • Set the scene on the scene and display it

A very simple code example to show how you can add it to a panel (from SwingNode Javadoc ):

 public class SwingNodeExample extends Application { @Override public void start(Stage stage) { final SwingNode swingNode = new SwingNode(); createAndSetSwingContent(swingNode); Pane pane = new Pane(); pane.getChildren().add(swingNode); // Adding swing node stage.setScene(new Scene(pane, 100, 50)); stage.show(); } private void createAndSetSwingContent(final SwingNode swingNode) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JPanel panel = new JPanel(); panel.add(new JButton("Click me!")); swingNode.setContent(panel); } }); } public static void main(String[] args) { launch(args); } } 
+15
source share

All Articles