JavaFX – Passing Arguments

I received a query on how to pass arguments in JavaFX. It basically depends on how we deploy the application. The application can be deployed using JavaWebStart, as an applet or launched from command line.

Lets take a simple application..

var text = Text {
    x: 10, y: 30
    font : Font size : 16 }
    content: "Argument {FX.getArgument( "key" )}"

The argument is passed as key-value pair. The value is retrieved using FX.getArgument( <key> ) method. Arguments can be passed to various deployment modes as shown below.

Command Line:

javafx -cp FXArguments.jar fxarguments.Main key="From Command Line"


<script src=";></script>
              archive: "FXArguments.jar",
              draggable: true,
              width: 250,
              height: 80,
              code: "fxarguments.Main",
              name: "FXArguments"
        } , {
              key: "from Applet"

Launch Applet Example

Java Web Start:

<jnlp spec="1.0+" codebase="dist" href="FXArguments.jnlp">
    <application-desc main-class="com.sun.javafx.runtime.main.Main">
        <argument>key=from Java Web Start</argument>

Launch Web Start Example