tillnagel / unfolding

A library to create interactive maps and geovisualizations in Processing and Java
http://unfoldingmaps.org
Other
478 stars 246 forks source link

Integration with JavaFx #114

Open FogiaFr opened 9 years ago

FogiaFr commented 9 years ago

I try to integrate an unfoldingmaps in JavaFx. To do so, I use the SimpleMapApp example. But I have either a blank screen or an exception (Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0).

Here is the example:

public class JavaFxIntegration extends Application {
    /** {@inheritDoc} */
    @Override
    public void start (Stage stage) {
        final SwingNode swingNode = new SwingNode();

        createSwingContent(swingNode);

        StackPane pane = new StackPane();
        pane.getChildren().add(swingNode);

        stage.setTitle("Unfoldingmaps in JavaFX");
        stage.setScene(new Scene(pane, 800, 600));
        stage.show();
    }

    /**
     * Integrate the unfoldingmaps in the swingNode.
     * @param swingNode parent node of the map.
     */
    private void createSwingContent(SwingNode swingNode) {
        SwingUtilities.invokeLater(() -> {
            SimpleMapApp map = new SimpleMapApp();
            map.init();

            JPanel panel = new JPanel();

            panel.setLayout(new BorderLayout());
            panel.add(map, BorderLayout.CENTER);
            panel.setPreferredSize(new Dimension(800, 600));
            panel.setBounds(0, 0, 800, 600);

            swingNode.setContent(panel);
        });
    }
}
FogiaFr commented 9 years ago

I found a 'workaround' by opening a JFrame with a PApplet inside outside of the Javafx components.

But it could be interesting to have a PApplet in a JavaFx Stage so if you find out how to...