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 -
- InterestingPhotos - Load photos from Flickr
- LocalSearch - Yahoo LocalSearch APIs
- ShoppingService - Yahoo Shopping-Service APIs
- ScreenshotMaker - Upload photos to Flickr
- PhotoFlockr - Search and load photos from Flickr
- RSSViewer - Loads well formatted RSS feedb
- WeatherWidget - Yahoo Weather RSS feed
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 http://blogs.sun.com/javafx/entry/how_to_use_javafx_in


thanks a lot Rakesh, this will help us knowing JavaFX better. Here is the original question post :
http://www.orkut.com/Main#CommMsgs.aspx?cmm=51255156&tid=5319884279710624083&start=1
Posted by Vaibhav Choudhary on April 09, 2009 at 10:49 AM IST #
Very good entry - thanks.
I would add one FAQ : Is it possible to include a JavaFX Scene in a regular Swing application ?
Answer in http://blogs.sun.com/javafx/entry/how_to_use_javafx_in
Posted by Sébastien Stormacq on April 09, 2009 at 12:38 PM IST #
Thanks Vaibhav. @Sébastien Thanks! I have added it to FAQ.
Posted by Rakesh Menon on April 09, 2009 at 03:04 PM IST #
Good one.
Have you considered sending it for official documentation on Sun site.
Posted by Vikram on April 09, 2009 at 03:39 PM IST #
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?
Posted by Harry on April 30, 2009 at 12:58 AM IST #
@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.
Posted by Rakesh Menon on April 30, 2009 at 11:15 AM IST #
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.
Thanks
Vikram
Posted by Vikram on October 22, 2009 at 11:26 AM IST #
@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.
Posted by Rakesh Menon on October 23, 2009 at 04:19 PM IST #