Geertjan's Blog

JavaFX, Google Maps, and NetBeans Platform

Geertjan Wielenga
Product Manager

Thanks to a great new article by Rob Terpilowski, and other work and research he describes in that article, it's now trivial to introduce a map component to a NetBeans Platform application. Making use of the GMapsFX library, as described in Rob's article, which provides a JavaFX API for Google Maps, you can very quickly knock this application together. Click to enlarge the image.

Here's all the code (from Rob's article):

preferredID = "MapTopComponent",
persistenceType = TopComponent.PERSISTENCE_ALWAYS
@TopComponent.Registration(mode = "editor", openAtStartup = true)
@ActionID(category = "Window", id = "org.map.MapTopComponent")
@ActionReference(path = "Menu/Window" /*, position = 333 */)
displayName = "#CTL_MapWindowAction",
preferredID = "MapTopComponent"
"CTL_MapTopComponent=Map Window",
"HINT_MapTopComponent=This is a Map window"
public class MapWindow extends TopComponent implements MapComponentInitializedListener {
protected GoogleMapView mapComponent;
protected GoogleMap map;
private static final double latitude = 52.3667;
private static final double longitude = 4.9000;
public MapWindow() {
setLayout(new BorderLayout());
JFXPanel panel = new JFXPanel();
Platform.runLater(() -> {
mapComponent = new GoogleMapView();
BorderPane root = new BorderPane(mapComponent);
Scene scene = new Scene(root);
add(panel, BorderLayout.CENTER);
public void mapInitialized() {
//Once the map has been loaded by the Webview, initialize the map details.
LatLong center = new LatLong(latitude, longitude);
MapOptions options = new MapOptions();
map = mapComponent.createMap(options);
//Add a couple of markers to the map.
MarkerOptions markerOptions = new MarkerOptions();
LatLong markerLatLong = new LatLong(latitude, longitude);
.title("My new Marker")
Marker myMarker = new Marker(markerOptions);
MarkerOptions markerOptions2 = new MarkerOptions();
LatLong markerLatLong2 = new LatLong(latitude, longitude);
.title("My new Marker")
Marker myMarker2 = new Marker(markerOptions2);
//Add an info window to the Map.
InfoWindowOptions infoOptions = new InfoWindowOptions();
infoOptions.content("<h2>Center of the Universe</h2>")
InfoWindow window = new InfoWindow(infoOptions);
window.open(map, myMarker);

Awesome work Rob, will be useful for many developers out there.

Join the discussion

Comments ( 3 )
  • Rob Terpilowski Friday, June 6, 2014

    Thanks Geertjan,

    Did you suppress the TopComponent tab by using a custom TabDisplayerUI class which you had detailed in a previous post:


    Or is there a more straightforward way to do it in version 8 of the RCP?

  • Geertjan Sunday, June 8, 2014

    No straightforward way yet, unfortunately. Just used the TabDisplayerUI approach.

  • JimR Tuesday, November 18, 2014

    How do I add this new Map module to the Palette for the GUI builder in Netbeans 8?

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.