Get started with JavaFX (BETA)

ArcGIS Runtime SDK for Java provides a JavaFX map component, FXMap, for developers to integrate ArcGIS mapping capabilities into their JavaFX apps. This topic describes how to configure your Eclipse environment for JavaFX development, and then provides a tutorial on how to create a simple JavaFX mapping app that uses the FXMap component. The remainder of the topic lists the types of layers that can be used in the FXMap component and provides links to other helpful JavaFX resources.

Beta:

The FXMap component is in BETA at this release, and as such should not be used in production applications.

Before following the steps in this topic, you must have installed ArcGIS Runtime SDK for Java on your Windows or Linux machine and installed the Eclipse plug-in.

Set up your Eclipse development environment

You can configure your Eclipse IDE to use the e(fx)clipse plug-in for JavaFX development. Optionally, you can also install the stand-alone application JavaFX Scene Builder 2 for visual UI design of JavaFX apps.

  1. Open Eclipse and install the e(fx)clipse tools plug-in. You can go to Help > Eclipse Marketplace to open the Eclipse Marketplace dialog box and search for it from there.

    Eclipse Marketplace dialog box

  2. If you use the above dialog box to search for the e(fx)clipse plug-in, click the Install button.
  3. Create a JavaFX project by going to New > Project > JavaFX > JavaFX Project.

    New Project wizard

  4. Click Next, give your project a name, and click Next again. In the Project Settings pane, click the Libraries tab, and add the ArcGIS Runtime Java Dependent JARs library.

    Java Settings for project

    Note:

    If you're using JDK 7, you'll need to add the jfxrt.jar from your JDK_HOME/jre/lib folder to your project's class path as an external jar. If you're using JDK 8, you do not have to do this.

    Click Next, and click Finish.

  5. Optionally, install JavaFX Scene Builder 2. You can configure Scene Builder to launch from Eclipse for visually editing FXML files.

You've set up your development environment and created a JavaFX project with one class called Main. Now, you're ready to create a simple JavaFX mapping app.

Create a simple app

This simple app will contain an FXMap component with an ArcGISTiledMapServiceLayer as its basemap.

  1. In Eclipse, open the Main.java class.
  2. Declare member variables for the FXMap and the basemap layer.
    public class Main extends Application {
    
      FXMap map;
      ArcGISTiledMapServiceLayer tiledLayer;
      ...
    }
  3. In the start method, replace the existing code with the following:
    try {
    
      // Create an instance of the JavaFX Map component
      map = new FXMap();
    
      StackPane stackPane = new StackPane();
      stackPane.getChildren().add(map);
    
      Scene scene = new Scene(stackPane);
    
      primaryStage.setTitle("JavaFX Map");
      primaryStage.setWidth(1000);
      primaryStage.setHeight(700);
      primaryStage.setScene(scene);
      primaryStage.show();
    
      // Create a tiled map service layer with an ArcGIS Online map service URL
      tiledLayer = new ArcGISTiledMapServiceLayer(
        "http://services.arcgisonline.com/arcgis/rest/services/NatGeo_World_Map/MapServer");
    
      // Add the layer to the list of layers in the map
      map.getLayerList().add(tiledLayer);
    			
    } catch(Exception e) {
      // handle exception as desired, minimally report it to console
      e.printStackTrace();
    }
  4. You are now ready to run the app. Right-click the Main.java class in the Package Explorer, and click Run As > Java Application.
  5. A map application will appear, similar to the following image:

    JavaFX mapping app

In Windows, by default, the map app is rendered using DirectX; in Linux, the map is rendered using OpenGL. If the map app is not created, ensure you have DirectX (Windows) or OpenGL (Linux) installed according to the system requirements.

Supported layer types

The following layer types are supported at this BETA phase of JavaFX support:

  • Tiled layers
    • ArcGISTiledMapServiceLayer
    • ArcGISLocalTiledLayer
    • OpenStreetMapLayer
    • BingMapsLayer
  • Dynamic layers
    • ArcGISDynamicMapServiceLayer
    • ArcGISLocalDynamicMapServiceLayer
    • WmsDynamicMapServiceLayer
    • ArcGISImageServiceLayer
  • Feature layers
    • FeatureLayer
  • Graphics layers
    • GraphicsLayer (both static and dynamic modes)

The following layer types are not supported at this BETA phase of JavaFX support:

  • ArcGISFeatureLayer
  • KMLLayer (Web Service)
  • MessageGroupLayer
  • CSVLayer

External JavaFX resources