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"

Applet:


<script src="http://dl.javafx.com/1.2/dtfx.js&#34;></script>
<script>
    javafx(
        {
              archive: "FXArguments.jar",
              draggable: true,
              width: 250,
              height: 80,
              code: "fxarguments.Main",
              name: "FXArguments"
        } , {
              key: "from Applet"
        }
    );
</script>

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>MainJavaFXScript=fxarguments.Main</argument>
        <argument>key=from Java Web Start</argument>
    </application-desc>
</jnlp>

Launch Web Start Example

Source: