JavaFX – Some FAQ

My colleague Vaibhav sent me a list of queries he got from forums. Here is an attempt to respond to them..

Can I embed JavaFX script into an HTML page, the way I can embed Java source code into a JSP page?
Java embedded in JSP page gets executed on server side. JavaFX is client side technology and gets executed on client system (similar to JavaScript). So you can embed JavaFX program in JSP as an Applet or using javafx script tag.

Can I include JavaFX code within a JavaScript function?
You cannot directly embed JavaFX code inside JavaScript. But you can very well integrate and interact with JavaScript using Java LiveConnect support.
Refer to this sample and post for more information.

Can I mix JavaFX and JavaScript together with php and jsp tags on an HTML page? What happens when I mix these technologies?
Yes. As mentioned in response to above question, you can mix JavaFX and JavaScript and interact between each other, share/update data. JavaFX and JavaScript executes on client side and PHP/JSP gets executed on server side.

Can I send HTTP commands directly to a server and then fetch and display the results in my browser?
How is JavaFX intended to interface with servlets?
How do I fetch data from a server and then immediately update a local HTML page display using JavaFX?
How can I mimic Ajax functionality?

Yes. Refer to this sample and post. JavaFX application read the RSS feed and parse the data. The data is then updated in the HTML page using JavaScript. You can also interface with any REST based service using HttpRequest and PullParser APIs.
There are many samples which demonstrates this –

Can I write a complete (but simple) server application that connects to the web and can recognize, parse and respond to simple messages from clients across a network?
Yes. JavaFX provides many APIs such as HttpRequest and PullParser which allow to read and parse XML/JSON data. You may also use any of existing Java technology in JavaFX for such interaction.

I can see how JavaFX instantiates a Swing object from a core class in the JRE. Can it also instantiate a custom object that I have written? How can I do this? What are the security implications?

You can encapsulate any existing Swing component using SwingComponent class so that it can be used as Node in JavaFX. SwingComponent.wrap(jComponent: javax.swing.JComponent) wraps an existing Swing component and returns SwingComponent instance. It just needs to be an instance of JComponent. Refer to this sample – ExercisingSwing. Security implications depends on the action performed by the component. Example: If its an unsigned Applet, access to system resource may be restricted. Those security restrictions will be handled by Java sandbox.

How do I interface a JavaFX script to a relational database?
One of power of JavaFX is that you can use any of the APIs provided by Java. So you can use all your existing database integration code, the same way as you do it in Java. Yes if you use any JavaSE specific APIs the application may not be portable to Mobile platform. So in such cases you may have to encapsulate the back end interaction using other means such as REST.
Refer to these posts:

Ajax pages have problems supporting browser ‘BACK’ button behavior. Can JavaFX overcome these problems and present users with the page-back behavior they have come to expect?
There is no built in back button support in JavaFX.

Can Google discover text intended to be displayed by a JavaFX-scripted Swing application?
No. JavaFX is deployed in compiled class file format. Google cannot directly read this data. Google can find you application if the HTML page in which this Applet is embedded has sufficient data to search and find this application.

How can I run JavaFX outside my browser as a local system scripting language?
You can deploy the JavaFX application in different formats – Standalone, JavaWebStart, Browser (and drag out of
browser) and Mobile (if the application use just Common profile APIs). The deployment mode can be chosen based on your requirement. Its not tied to the application code.

Is it possible to include a JavaFX Scene in a regular Swing application?
Answer in

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


About Rakesh Menon

10 Responses to JavaFX – Some FAQ

  1. thanks a lot Rakesh, this will help us knowing JavaFX better. Here is the original question post :

  2. Very good entry – thanks.
    I would add one FAQ : Is it possible to include a JavaFX Scene in a regular Swing application ?
    Answer in

  3. Rakesh Menon says:

    Thanks Vaibhav. @Sébastien Thanks! I have added it to FAQ.

  4. Vikram says:

    Good one.
    Have you considered sending it for official documentation on Sun site.

  5. Harry says:

    Thanks for your intuitive articles.
    We are trying to implement a JavaFx dash board in an ASP portal. And web service is the data provider for the dash board based on login user id. Is this possible with JavaFX/ASP combination?

  6. Rakesh Menon says:

    @Harry Yes. Its feasible. JavaFX (in applet mode) can be embedded in any HTML page and can process data from any webservice. Above samples obtain data from various sources such as flickr/yahoo, google etc.

  7. Vikram says:

    Hi Rakesh
    Thanks for our support you are providing to us.
    In my application I am using Javafx 1.1 in this i am showing a list of contents which changes dynamically based on radio button selection for this i am using javafx swinglist and swinglistitem but instead of that i want to show list of checkboxes which will change dynamically.
    can u help in this.

  8. Rakesh Menon says:

    @Vikram Thanks! Components under javafx.ext.swing are just wrappers over existing Swing components. So you may create your own swing component and use SwingComponent.wrap(<javax.swing.JComponent>) so as to get instance of SwingComponent which can be added to JavaFX UI.

  9. ayushi says:

    Hello Rakesh
    Thanks for these information.Indeed it help a lot.I am new to javafx scripting. I was just wondering where did u get the part the "rssviewer.Main" as code from a piece of work u did.
    I am trying to apply what u have done with my javafx application but i cant see any .main file…can u help please!!!!

  10. Rakesh Menon says:

    @ayushi Thanks.. I think you are referring to RSS-Viewer sample.. The source is available along with the Sample.. "rssviewer" is package name and "Main" is class name..
    Source available here..

Leave a Reply

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

You are commenting using your 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: