I am developing a Desktop application in Java using JavaFX for the GUI. A vital part of the program consists of a map for which I've decided to use JxMaps since it being a powerful framework with a very good documentation made it the best option.
However, the problem is that it is integrated in Swing, which I thought shouldn't be an issue since I found the code from this example. In fact, it compiles, but for some reason I get "Application Not Responding". I assume it has to do with this integration as the maps work perfectly when I run them outside the JavaFX application.
My current program looks exactly like this:
Main.java
import javafx.application.Application;
import javafx.embed.swing.SwingNode;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javax.swing.*;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
final SwingNode swingNode = new SwingNode();
createMap(swingNode);
StackPane pane = new StackPane();
pane.getChildren().add(swingNode);
primaryStage.setTitle("Fields Map");
primaryStage.setScene(new Scene(pane, 700, 500));
primaryStage.show();
}
private void createMap(final SwingNode swingNode) {
final FieldsMap mapView = new FieldsMap();
SwingUtilities.invokeLater(() -> swingNode.setContent(mapView));
}
}
FieldsMap.java
import com.teamdev.jxmaps.*;
import com.teamdev.jxmaps.swing.MapView;
public class FieldsMap extends MapView {
public FieldsMap() {
setOnMapReadyHandler(new MapReadyHandler() {
@Override
public void onMapReady(MapStatus status) {
// Check if the map is loaded correctly
if (status == MapStatus.MAP_STATUS_OK) {
// Getting the associated map object
final Map map = getMap();
// Creating a map options object
MapOptions options = new MapOptions(map);
// Creating a map type control options object
MapTypeControlOptions controlOptions = new MapTypeControlOptions(map);
// Changing position of the map type control
controlOptions.setPosition(ControlPosition.TOP_RIGHT);
// Setting map type control options
options.setMapTypeControlOptions(controlOptions);
// Setting map options
map.setOptions(options);
// Setting the map center
map.setCenter(new LatLng(map, 35.91466, 10.312499));
// Setting initial zoom value
map.setZoom(2.0);
}
}
});
}
}
This last one being an exact copy of the Map example in their Github repository.
Finally, the exact output in my console and what I see when I right-click on the java app can be seen here:
Thanks in advance.
Vitaly from JxMaps team here. At the moment JxMaps does not support JavaFX. We’re working on implementing JavaFX support in one of the next versions. Drop us a line via email and we’ll inform you, once the version with this feature is out.