Tuesday May 25, 2010

Thank You!

I was inspired by Jim Weaver and Stephen Chin to start blogging. Jonathan Giles provided the launch pad via his "Java desktop links of the week". Philippe Lhoste (PhiLho in Forums, you cannot miss him!) inspired to write more. In less than one year this blog was made popular by all of you and was added to "Oracle's Java Bloggers" list. Feels great to see the name along with some of the greatest people in industry

None of these would have been possible without your encouragement and support. I would like to say to all of you. It was really nice interacting with you. Google-Analytics shows huge number of unique visitors, I hope this was of help to at-least few of them

Unfortunately today is my last day at Sun-Oracle. I had to take this difficult decision to end a decade long association with Sun. I'll continue to blog at WordPress


Hope to have your continued encouragement and support

Monday Aug 31, 2009

JavaFX - Applet Startup Time

We keep getting various numbers related to JavaFX applet startup time. Yes this is very important and we need a consistent way to measure this and compare. Here is an attempt..


When the page is loaded, the system time is noted using JavaScript. Time is again noted once Applet is loaded. Difference between time obtained in Applet and JavaScript is computed to be startup time. I think this will be fair and consistent way to measure startup time. This requires JavaSE 6 Update 10 and above. It will be good to try out a few times and get the average number..

<script src="http://dl.javafx.com/1.2/dtfx.js"></script> <script src="/rakeshmenonp/resource/Startup/Startup.js"></script>

User Without JavaFX
Rakesh Menon453.000.70
Pär Dahlberg-7.270.66
Julien Buret-1.710.32
Philippe Lhoste-3.420.98
Ernie Kent-4.730.66
Carl Dea - FF-5.740.63
Carl Dea - IE-3.340.74
Simon Brocklehurst-3.120.79
Tom Eugelink-2.680.64
GC - WinXP-64bit FF-64bitError
Carl Antaki-4.060.67
Nick Apperley-3.270.83
Andy Xie478.321.05
Wojciech Halicki-Piszko-4.450.8
Endre Stølsvik723.80-
Chui Tey - Chrome
Chui Tey - MSIE 8.0.6001.18702IS-3.220.70
Chui Tey - FF 3.0.10-4.130.70
JosK (Intel Core 2CPU 4300@1.8GHZ (1,93GB) 512RAM) - Chrome
JosK (Intel Core 2CPU 4300@1.8GHZ (1,93GB) 512RAM) - Chrome
JosK (Intel Core 2CPU 4300@1.8GHZ (1,93GB) 512RAM) - IE 8.0.6001.18702-8.331.06
Jonathan (Quad Core Q9300 @ 2.5GHZ, 4GB ram JRE 1.6u15)15.50-0.52
Thierry (2 year olds windows dual core basic PC)17.503.10-
Robrecht (Windows xp SP2 Intel Core 2 cpu T5600 @ 1,83GHz, 2GB Ram jre: 1.6.0_15)4.832.800.62
Venkateswara Rao Desu (Fedora 9 JDK 1.6_10)Applet not initialized
André Costa-1.910.42
Joeri Sykora (jdk 1.6.0_16 in Firefox 3.5.3)-1.020.65
Thustle (1.6.0_16 on Chrome v3 on Vista 32bit Intel Core2 Quad Q6600 2.4GHz 4GB)-9.300.74
Vance (Intel Core 2 Duo P8700 2.53GHz/1066Mhz RAM:4GB, DDR3, 1067 MHz, Ubuntu 9.10, FireFox 3.5.5, JRE: 1.6.0_15, Connection: comcast high-speed cable)
Venkateswara Rao Desu (Fedora 11 Firefox 3.5.5 Sun Java Plugin)17.00-0.70
Venkateswara Rao Desu (Windows XP Java 1.6.0_18)9.3-0.38
Jor (WinXP, FF 3.5.7, Java 1.6.0_17)36-0.21


  • Without JavaFX Runtime - After clearing Java Web Start cache - [ javaws -uninstall ] May have to wait for sometime as clearing process may be running in background. This is the time taken to download JavaFX runtime and load the applet.
  • Load Applet - Launch browser and load applet (JavaFX runtime already installed)
  • Re-Load Applet - Re-load the page after loading applet
  • Duration - specified in seconds

Please launch the applet and let me know the start-up time with system configuration and connection speed.. Thanks in advance..

Monday Aug 03, 2009

JavaFX - YouTube

In previous blog I gave a simple example for JavaFX - JavaScript communication. Here we will see how to utilize this feature so as to integrate YouTube with JavaFX browser deployment. YouTube provides Data and Player APIs. We can utilize them to integrate YouTube presentation layer to JavaFX.

Given below is JavaFX app which uses YouTube Data APIs to search for videos with specified tag and displays the thumbnail images. User can click on thumbnail to view the video. The video can be controlled from JavaFX using JavaScript APIs. I'm sure a good designer can provide a much better seamless integration

<script src="http://dl.javafx.com/1.2/dtfx.js"></script> <script src="/rakeshmenonp/resource/JavaFXYT/JavaFXYT.js"></script>

Click on above image to launch the applet.
Note: Require JavaSE 6 Update 10 or above.
I'm not responsible for content shown in video

I have used YouTube Search APIs. It provides output in various formats - atom, rss, json and json-in-script. I have used the default ATOM format. Even though its using ATOM format, most of required attributes are provided in custom tags as shown below. Hence even though I used AtomTask to parse the feed, I still had to parse the custom tags in onForeignEvent : function(:Event):Void method. Details of parser is available in YTDataTask.fx.

    <media:category label='Science &amp; Technology' scheme='.../categories.cat'>Tech</media:category>
    <media:content url='http://...app=youtube_gdata' type='application/x-shockwave-flash' yt:format='5'/>
    <media:content url='rtsp://rtsp2.youtube.com/.../video.3gp' type='video/3gpp' yt:format='1'/>
    <media:content url='rtsp://rtsp2.youtube.com/.../video.3gp' type='video/3gpp' yt:format='6'/>
    <media:credit role='uploader' scheme='urn:youtube'>terrencebarr</media:credit>
    <media:description type='plain'>Terrence Barr...</media:description>
    <media:keywords>JavaFX, JavaFX Mobile</media:keywords>
    <media:player url='http://www.youtube.com/watch?v=6LdFq8T0Uys'/>
    <media:thumbnail url='http://i.ytimg.com/.../default.jpg' height='90' width='120' time='00:04:25.500'/>
    <media:thumbnail url='http://i.ytimg.com/.../2.jpg' height='90' width='120' time='00:04:25.500'/>
    <media:thumbnail url='http://i.ytimg.com/.../1.jpg' height='90' width='120' time='00:02:12.750'/>
    <media:thumbnail url='http://i.ytimg.com/.../3.jpg' height='90' width='120' time='00:06:38.250'/>
    <media:thumbnail url='http://i.ytimg.com/.../hqdefault.jpg' height='360' width='480'/>
    <media:title type='plain'>Getting Started with JavaFX Mobile...</media:title>
    <yt:duration seconds='531'/>

YouTube provides "Chromeless Player" with JavaScript API support. We can obtain the videoid using above Data APIs and pass this to player using JavaScript APIs. We can perform operations such as - load video, play, pause, stop, seek, mute/un-mute - on video. Refer to JavaScript API documentation for more information.

All these APIs are encapsulated in a file - JavaYT.js. A Java wrapper for this javascript file is provided so as to invoke these APIs from Java - JavaYTUtil.java. This in turn uses JavaScriptUtil.java as shown in previous post.

Both YouTube player and JavaFX is added to a Table so as to render them together. Please refer to JavaFXYT.html for more information.

Try it out and let me know feedback

<script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="/rakeshmenonp/resource/JavaFXYT/zoneit.js"></script>

Tuesday Jul 28, 2009

JavaFX - JavaScript Communication

There is a tutorial on JavaFX Script - JavaScript Bridge, JavaFX Sample, Plug-In Live Connect and Carl's blog to list a few.. But still see questions about this (JavaSE Plug-In) feature. Hence just thought about writing a blog to demonstrate this..

I think the question primarily arise because, people have tried it but it doesn't seem to work. The feature is stable only with JavaSE 6 Update 10 and above. So if you are using older JRE (as in default settings of Mac) the feature will not work as expected.

In below example, I have two user interface. One with HTML and another in JavaFX. When I click on HTML buttons it will invoke Java API and show message box using javax.swing.JOptionPane. When I click on JavaFX buttons, it will call JavaScript method such as alert, confirm, prompt to show message box.

<script src="http://dl.javafx.com/1.2/dtfx.js"></script> <script src="/rakeshmenonp/resource/JavaFXJavaScript/JavaFXJavaScript.js"></script>

Click on above image to launch the applet

JavaScript methods are invoked from Java or JavaFX using netscape.javascript.JSObject. An instance of JSObject can be obtained using static method JSObject.getWindow(< applet >) by passing the current applet instance as argument.

Applet instance can be obtained from JavaFX as shown below:

var applet = FX.getArgument("javafx.applet"as Applet;

Next we need to get instance of JSObject. These classes are available in plugin.jar. So we need to include explicitly plugin.jar in classpath. Instead we can also use reflection to invoke these methods. I have used reflection and created a wrapper - JavaScriptUtil. This can be instantiated by passing above applet instance.

A series of method to show message box is added both JavaScript and JavaFX as shown below.


function show_alert() {
    alert("JS: I am an alert box!");


public function showAlert() : Void {
    JOptionPane.showMessageDialog(null, "FX: I am an alert box!");

I have prefixed the message with "FX" and "JS" so as to identify the origin of message box.

Invoke JavaFX method from JavaScript:

var applet = document.getElementById('JavaFXJavaScript');
// Invoke JavaFX method from JavaScript

The applet element is obtained using its id

           codebase: "dist",
           archive: "JavaFXJavaScript.jar",
           draggable: true,
           width: 250,
           height: 120,
           code: "javafxjavascript.Main",
           name: "JavaFXJavaScript",
           id: 'JavaFXJavaScript'

Invoke JavaScript method from JavaFX:

var jsObject = netscape.javascript.JSObject.getWindow(applet);

Since we have wrapped all JSObject methods in JavaScriptUtil we may invoke JavaScript method as shown below.

var applet: Applet = FX.getArgument("javafx.applet"as Applet;
var jsObject = new JavaScriptUtil(applet);

Please refer to JavaFXJavaScript.html and Main.fx for more details.

Java Plug-In LiveConnect API Documentation:

Try it out and let me know feedback

<script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="/rakeshmenonp/resource/JavaFXJavaScript/zoneit.js"></script>

Thursday Mar 05, 2009

JavaFX - News Widget

This is an attempt to answer several queries in one go. Lets see if it helps..
  1. Can I embed JavaFX in JSP, ASP, PHP, JSF,...
    (Endless several other web technologies)?
  2. Can JavaFX dynamically interact with html page via JavaScript?
  3. Is it feasible to implement JavaFX <-> JavaScript communication?
  4. Can JavaFX retrieve data from external services/resources?

Answer is YES! to all of above. Lets try to prove that..

We have a JavaFX Sample - RSS-Viewer which we will try to customize and integrate it into this blog. RSS-Viewer can retrieve data from various RSS feeds. It will parse the feed using JavaFX parser and render the HTML data in browser.

By default the application loads the feed from Yahoo! news. We will customize it so as to load the feed from Google News. The application accepts an argument rss_url which can be used to specify the RSS feed.

Now how will we incorporate this widget into this blog? We need to create a <div> in HTML which will act as placeholder for embedding the HTML data from JavaFX. We will update the content of this <div> using JavaScript.

<div id="ChannelData" style="text-align: center;"></div>

Now we will write a JavaScript method which will update the data from JavaFX.

function updateChannelData(channelData) {
    document.getElementById("ChannelData").innerHTML = channelData;

JavaFX will invoke updateChannelData( <data> ) with data from RSS feed and update the content. Now we need to include the JavaFX Widget. For this we need to include the JavaScript dtfx.js and call javafx function passing the application attributes as shown below.

<script src="http://dl.javafx.com/1.2/dtfx.js"></script>

<table width="40%" border="1" cellpadding="10" cellspacing="0">
      <td align="center">


              archive: "http://javafx.com/samples/RSSViewer/webstart/RSSViewer.jar,",
              width: 610,
              height: 62,
              code: "rssviewer.Main",
              name: "RSSViewer"
              isApplet: "true"
              js_mode: "true"
              rss_url: "http://news.google.com/news?pz=1&ned=us&hl=en&topic=w&output=rss"
          function updateChannelData(channelData) {
            document.getElementById("ChannelData").innerHTML = channelData;
        <div id="ChannelData" style="text-align: center;"></div>

After embedding above code in your html you must be able to load and view Google News.

Now we have incorporated an existing widget into html page. It also uses JavaFX <-> JavaScript interaction and loads the data from external service - Google News.

Refer to LiveConnect Support in the Java™ Plug-In Technology for more information on Java <-> JavaScript communication.

But did I prove the first point - Can I embed JavaFX in JSP, ASP, PHP, JSF,...??. May be not? Please try to follow above steps and try to incorporate this widget into your page and let me know how things go. You must be able to provide any well formatted RSS feed as rss_url.

For standalone mode

<script src="http://dl.javafx.com/1.2/dtfx.js"></script> <script> function updateChannelData(channelData) { document.getElementById("ChannelData").innerHTML = channelData; } javafx( { archive: "http://javafx.com/samples/RSSViewer/webstart/RSSViewer.jar,", width: 610, height: 62, code: "rssviewer.Main", name: "appl" } , { isApplet: "true", js_mode: "true", rss_url: "http://news.google.com/news?pz=1&ned=us&hl=en&topic=w&output=rss" } ); </script>

<script type="text/javascript">var dzone_url = "http://blogs.sun.com/rakeshmenonp/entry/javafx_news_widget";</script> <script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script>


The views expressed on this blog are my own and do not necessarily reflect that of my organization


« June 2016