Archive for the ‘JavaFX’ Category


I always thought that there is ought to be better way to develop JavaFX application, with kind of similar and gratifying experience as developing Java Swing application. Traditionally in developing desktop application, one normally develop and test using class file to save time, and only uses JAR file for deployment (or if running in mobile emulator or device). However with the advent of RIA platform, the trend is to use a application container file (eg jar, swf) as default way of development since it facilitates seamless running in several modes without hassle (eg as Applet, webstart, and mobile device). Unfortunately, this is rather inefficient if one is developing desktop application, or experimenting with ideas. Unnecessary waiting time only disrupts the creativity and programming flow. Saving a few seconds for every run will accumulate into significant saving of time. Besides, it is rather counter-productive to use container file as the only mode of development if the technology can support alternative efficient way.



Read Full Post »

Tested on
– Windows Vista/7
– NetBeans 6.71 with JavaFX

If you need to customize the AutoIt script , you need to install the AutoIt v3 environment (http://www.autoitscript.com/)
Note that AutoIt ONLY works in Windows environment.


NetBeans is the official IDE for JavaFX development. However, the latest v6.71 (or beta 6.8) of NetBeans is unable to beautify JavaFX Script (JfxScript) code as the “Format” option is not working (It just do nothing.  See Bug acknowledgement).

The code beautifier is one of the most important tools for learning and using  JavaFX as most raw code copied from Internet/ebook tends to be unformatted, making it hard to read and use. Performing manual format is just too tedious. So until the next NetBeans’s release, users have to resort to using painstakingly manual code formatting .

Code beautifier turn this (The following JfxScript code is formatted in NetBeans ! Read on to see how it’s done.)


into this



Read Full Post »

As the title has partly hinted, those objectives of the post are to touch on issues and solutions that make JavaFX Script a better scripting language by promoting good practices learnt from mature language, or to be more specific, its parent language, Java. The fact that JavaFX Script derives its name partly from the Java moniker means that it certainly deserves high expectation that worthy of its heritage. JavaFX Script might be new to the game but it has the advantages of getting its foundation right by learning from its predecessors eg ActionScript, Groovy.

The reasons why all these 3 areas are discussed together rather than as separate posts are  because they are closely related, and one can’t have it working correctly without effectively addressing the other. These suggestions and questions are materialized after spending some time exploring on the ‘intricacies’ of JavaFX Script and pondering on those issues that developer will encounter using JavaFX Script.

We might think that JavaFX Script might be the ideal language because it combines the the best of both worlds, that is the flexibility and ease of scripting language and robustness and predictability of a compiled language. As we should see later that it often not the case, there exists a impedance mismatch between two programming language type that if not resolved will create a language of confusion instead (Though this is nothing new to JavaFX Script as it is quite prevalent in scripting languages that provides OOP capability)


Read Full Post »

As JavaFX is near its imminent final release, JavaFX Script is still in the flux of development and uncertainty. As deadline looms near, JavaFX Script is still carving its identity and finalizing its feature set. The specification of the language is very much incomplete even though some documentation exists. Developers will still need to test and explore to determine how JavaFX Script will work. Hence will it be good idea if JavaFX Script takes on the existing proven idea of Java and JavaScript to lessen the learning curve and make it more attractive to Java developers as well as web developer ?

The followings are the suggestion to improve JavaFX Script by making it more consistent, easier to develop and test by leveraging on some language features that familiar to both Java developer and Javascript developer.

I am surprised that blogs on JavaFX  lack discussion about improving the JavaFX Script language but rather focusing on how to use language to get working application. If the language feature does not seem obvious maybe it is the language that need revamping.


Read Full Post »

To those Java developers learning JavaFX Script will be dismay to find that the useful interface and enum Java language constructs are not supported. Even though the ability to leverage and reuse existing Java myriad library is quoted as one of the greatest strength of JavaFX, JavaFX’s support for datatypes are currently limited to primitive data wrappers (Integer, Boolean, Number, String) and explicit class. Even though JavaFX Script may not explicitly support interface and enum , however all is not lost and developers can use workaround that involves some extra works. This solution is possible because JavaFX uses Class, the foundation of object-orientated programming, and that interface and enum are both closely related to class. In short, the interface construct allows constant declaration and provides method declaration without body. The enum provides a more powerful way of defining constant which is more elegant and less error-prone. Adapter Java class may include inner class and inner interface and still compile fine in JavaFX Script, however these will be ignored in JavaFX Script.

See  http://java.sun.com/developer/technicalArticles/scripting/javafx/javafx_and_java/

Recently, having browse through the source code in JavaFX, it evidently that interface and enum are indeed been used in JavaFX Script (though directly using interface, enum keywords).  It turns out that interface can be defined in the following manner. Note that user has to define all the interface methods even if one used a adapter class to provide dummy implementation for the interface. Interestingly, variable defined in interface and enum can be used in JavaFX Script like in Java class. Do take note that there is no switch statement in JavaFX Script.

var variable:Interface = Interface { body }

eg taken from Frame.jx in JavaFX Script Source Code

private attribute winListener: java.awt.event.WindowListener;

winListener = java.awt.event.WindowListener { // WindowAdapter has no effect. One still need to define all the interface method of WindowListener)
                                  public function windowClosing(e:WindowEvent):Void {
                                      if (disposeOnClose) {
                                           frame.dispose(); // fix me…
                                      if(onClose != null) {
                                      if (hideOnClose) {
                                          visible = false;
                                          showing = false;

… define rest of WindowListener’s methods



JavaFX Script can reuse Java’s class and methods through using following Adapter pattern but can Java uses function and class of JavaFX Script ?


JavaFX Script is still evolving but at this point the answer is NO (even though there might be just workaround) because syntax difference between JavaFX Script’s class and Java’s class. Function in JavaFX is a first-class object and there is also no concept of function in Java. So if JavaFX Script wants to pass data and object to Java’s class and method then pass it using standard primitive type wrapper and Java class.


The following table shows how to convert/wrap Java’s interface and enum into compatible implementation (class/method) to be used in JavaFX Script.


Read Full Post »


Will update more questions here.

JavaFX Script


Does JavaFX Script required a main method as in Java ?

No. JavaFX Script as its name implies behave just like any other script language that execute code directly from the top to bottom in contrast with Java that exec


How does JavaFX Script uses command line argument ?

JavaFX Script support command line argument through the sequence __ARGS__ .


import java.lang.System;
for (arg in __ARGS__)
{  System.out.println(“argument{indexof arg} is:{arg}”); }

Thank to James Weaver for this information and code.


What are some of the language differences between JavaFX Script and Java ?
Java developer learning JavaFX Script might want to know that JavaFX Script has:

  • No inner class support
  • No static and instance  initializer
  • No constant support. eg final variable
  • No interface, enum, generics
  • Instance variable defined in class is considered as attribute, everything else defined through var 


Can JavaFX Script call existing Java class ?

Yes. Just like Java through import statement. However take note of the implication due to the language difference. Retrieving return value or passing argument that uses interface, enum will not work.The compilation will give errors even though the Netbeans IDE might not report it immediately using the real-time error detection.(There are ways to access it in JavaFX Script).  See Using Java’s Interface and Enum in JavaFX Script


Can I program GUI using Swing components in JavaFX ?

You can still instantiate Swing components in JavaFX but will be severely handicapped in developing GUI because no event can be added through add listener methods since JavaFX does not understand interface. If still insisting on using Swing components, it will be more appropriate to program in Java. JavaFX has its own way of building GUI through its syntax and components.


What are the audio and video formats currently supported in the Java Media Component in JavaFX ?
Can I program GUI using Swing components in JavaFX ?

  • Container Types:
    ASF (Advanced Systems Format),MPEG-1, AVI (Audio-Video Interleaved),WAVE, MIDI (Standard MIDI)
  • Encoding Types:
    WMAUDIO8 (WindowsMedia Audio 2/7/8),WMSCREEN (Windows Media Screen), WMVIDEO9 (Windows Media Video 9), Voxware, MS MPEG-4, WMVIDEO7 (Windows Media Video 7), MPEG11 Video, MPEG-1 Audio, Uncompressed video (RGB/YUV/RLE), PCM, ADPCM, MP3, MIDI

    Microsoft’s audio and video proprietary formats are supported in Windows only (DirectShow).

Taken from http://www.javafx.com/htdocs/previewfaq.html


What is the main difference between XML-based RIAs and JavaFX ?

Popular RIA platforms like Silverlight and Flex which use XML to define GUI, data-binding,  provides a clear separation between declarative and programmatic functions. These solutions use XML for as declarative language to build GUI, and use full-fledged programming languages to program the behaviour. For example, in Flex, the declarative component is the MXML (using file with extension .mxml and the programmatic component is ActionScript (file Extenson .as) . JavaFX takes a different approach by unifying these functions using a scripting language in JavaFX Script (file Extension .fx ) . Which approach is better is a matter of preference. Some will prefer XML-based approach as it is more popular since many are already familiar with XML due to HTML, and less confusing due to distinctive separation between the functions. Others will welcome the power and flexibility of the integrative approach in JavaFX Script.

Read Full Post »