Home > javafx > JavaFX – Passing Arguments

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="http://dl.javafx.com/1.2/dtfx.js&#34;></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


var dzone_url = “http://blogs.sun.com/rakeshmenonp/entry/javafx_passing_arguments&#8221;;
var dzone_style = ‘2’;

digg_skin = ‘compact’;
digg_window = ‘new’;

Categories: javafx Tags: ,
  1. June 13, 2009 at 2:56 AM

    Is it also possible to pass in an argument as a URL parameter for a web start application?
    Like this:

  2. June 13, 2009 at 10:28 PM

    @Pär Dahlberg That wont be possible. One way is to write a servlet with content-type as XML which will dynamically generate the jnlp file. This way we can pass the arguments to servlet which returns the required jnlp file.

  3. June 22, 2009 at 1:12 PM

    Hadn’t thought of that. Thanks 🙂

  4. LaoZhang
    June 24, 2009 at 8:06 PM

    i’m just looking for this, thanks a lot Rakesh!

  5. June 24, 2009 at 11:18 PM

    @LaoZhang Glad! Thanks!

  6. October 26, 2009 at 11:25 AM

    How do I pass jvm arguments to the applet? I’m running up against a problem with localization and cant’ figure how to translate this
    -Duser.language=fr -Duser.country=CA
    in to something that can be used by the applet. I’ve tried adding
    <param name="java_arguments" value="-Duser.language=fr -Duser.country=CA"/>
    inside the <applet-desc> tag inside the jnlp file, but no luck.

  7. Rakesh Menon
    October 27, 2009 at 12:00 AM

    @Sean C You can use property tag inside resources in jnlp to set System properties.
    <property name="key" value="overwritten"/>
    There are some security restrictions for unsigned applets.
    Please refer to jnlp syntax for more info : http://java.sun.com/javase/6/docs/technotes/guides/javaws/developersguide/syntax.html#resources

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: