JavaFX How to - List Application Context information








Question

We would like to know how to list Application Context information.

Answer

import javafx.application.Application;
import javafx.application.HostServices;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
/*w w  w  .  j av a  2s .c  om*/
public class Main extends Application {
  public static void main(String[] args) {
    Application.launch(args);
  }

  @Override
  public void start(Stage stage) {

    Button openURLButton = new Button("Go!");
    openURLButton.setOnAction(e ->{
      HostServices host = this.getHostServices();
      
      System.out.println("CodeBase:"+host.getCodeBase());
      
      System.out.println("DocumentBase:"+host.getDocumentBase());
      
      System.out.println("Environment:" + host.getWebContext());
      
      System.out.println("Splash Image URI"+host.resolveURI(host.getDocumentBase(), "splash.jpg"));    
    });

    Scene scene = new Scene(openURLButton);
    stage.setScene(scene);
    stage.setTitle("Knowing the Host");
    stage.show();
  }
}