Archives for the month of: July, 2011

I was just given notice that we were allowed to share an internal FXML document originally written by Greg Brown, a member of the JavaFX controls team. What follows is a painfully slow (and very labour intensive!) PDF to HTML conversion We’ve updated the document, and instead of re-translating it every time, I will now just be posting the PDF file directly. If you find any mistakes, please leave a comment (or email me), and I’ll update the document. I also have to add the normal disclaimers: this is a draft document, and it is likely that it may change leading up to the GA release of JavaFX 2.0. With that out of the way, read on and enjoy! :-)

Download the latest 'Introducing FXML' document

In case you’re wondering what FXML is, FXML is a scriptable, XML-based markup language for constructing Java object graphs. It provides a convenient alternative to constructing such graphs in procedural code, and is ideally suited to defining the user interface of a JavaFX application, since the hierarchical structure of an XML document closely parallels the structure of the JavaFX scene graph.

Another month down, leaving only two months until JavaOne 2011. Of course, the big news last week was the release of Java 7. Besides that, there are some good links this week (as always!), so let’s get into the rest of this weeks links :-)

  • JavaFX 2.0 beta b37 was released, to enable developers another weeks worth of access to FXML, the XML-based markup language for (optionally) creating JavaFX user interfaces. It’s optional because you are by no means forced to build UIs in FXML – you can continue to freely use Java, or indeed, any JVM-based language. It’s just another option for those of you that like using XML for UI layout, and certainly it is a great format for tooling support and UI interchange.
  • GroovyFX continues to flourish with improved support for JavaFX 2.0 and improved GroovyFX documentation. I have to wonder, are any other JVM-based languages doing similar? Get in touch with me if  you are working on something!
  • There is a brief video on YouTube with Jim Weaver presenting about ‘JavaFX in the real world‘. Of note is that Jim makes use of Grezi in his presentation, which I have linked to in previous weeks.
  • At OSCON/Java, Jim Weaver promised to make available the source code for his EarthCubeFX application, which is a port of his original EarthCube application from JavaFX 1.3 to use the latest 2.0 beta builds. You’ll also note that he has a YouTube video which demonstrates EarthCubeFX running on Mac OS X.
  • Jonathan (not me) has blogged over at The Java Tutorials’ Weblog about the top five docs to introduce yourself to JavaFX 2.0.

That’s all folks! I hope you found something useful in the links above, and as always: keep up the great work, blog about what your discovering, and feel free to contact me with any links of interest! Catch you all in a weeks time :-)

 

We’ve just rolled out another JavaFX 2.0 beta build (build 37) to get you access to FXML as quickly as possible (rather than wait until next weeks b38 release).

FXML is a scriptable, XML-based markup language for constructing JavaFX user interfaces. It is an alternative option for building your user interfaces, in addition to using Java, or any other JVM-based language (or a wrapper like GroovyFX). To quote the JavaOne session abstract on FXML: “The hierarchical structure of an XML document closely parallels the structure of the JavaFX scene graph, making it easy to visualize the resulting output. Event handlers can be written with any JVM-compatible scripting language, such as JavaScript, Groovy, or Clojure. Additional features include on-the-fly localization, dynamic data binding, and code modularization.”

Whilst we rolled out b37 as soon as we could to get you access to FXML, we are still working on a sample of how to use it – and this will be in the next public beta build. Additionally, we are busily working on plenty of documentation on how to use FXML which will become available in our documentation area as soon as it is ready. Who knows, if there is enough pleading in the comments on this blog post, maybe I can try to get someone to write a blog post here about the wonders of FXML :-)

Of course, along with b37 including FXML, it also contains a weeks worth of bug fixes, performance tweaks and necessary API changes (based in no small part on your feedback to our Jira tracker). As always, I look forward to hearing your feedback on this latest release. The best place to discuss JavaFX 2.0 is at the OTN forum, where many of the JavaFX team lurk. However, file your bug reports / request for enhancements directly to our Jira tracker if you want to maximise your chances of being heard!

Here we go again – yet another intro to a blog post series that hasn’t changed much at all in the years it has been running (both here and on my personal blog)! For that reason, let’s just jump into the links (which, lets admit it, is the real reason you’re here). Enjoy! :-)

Also, I thought I’d link to the JavaOne conference sessions, which are now published online. For those mostly interested in JavaFX, you might want to refine the search criteria to the Java SE track. Additionally, a tutorial has appeared online recently that details MigLayout. Despite being most commonly used in the Swing world, it has been adapted to numerous other UI toolkits, including SWT and JavaFX. The JavaFX version is available online (but I’d be remiss if I didn’t also mention that the JavaFX SDK comes with the GridPane layout, which may meet your needs).

Keep up all the hard work folks. Catch you all next week.

A new JavaFX 2.0 beta build has been made available. The main feature of this release are:

  • The worker threading API that Richard has discussed previously.
  • Support for rich text editing (via the new HTMLEditor control)
  • A FileChooser dialog.
  • FXML, which is a scriptable, XML-based markup language for constructing JavaFX user interfaces. Turns out I was wrong on this – we didn’t get this into this build. It will definitely be in the next one however!

In addition, I believe that both the online API docs, as well as the developer documentation, have been updated, and additional tutorials added. These changes may take a short while to be reflected online however are now online.

I recommend that everyone that is working with JavaFX 2.0 beta builds update to the latest build as soon as possible, as that helps to uncover new issues and also reflects the very latest features and functionality. From my understanding the download rate for these beta builds has been huge, so thanks to everyone for testing the beta releases and giving such valuable feedback. I look forward to hearing your feedback on this latest release. The best place to discuss JavaFX 2.0 is at the OTN forum.

A relatively quiet week in the world of JavaFX, but hopefully you can find a link or two of interest! :-) Let’s jump into them…

That’s that for another week. As always, feel free to email me links you want included – I appreciate the hints you all give me! Anywho, catch you all again in a weeks time :-)

It was my pleasure to recently come across the GroovyFX project, which works to make building JavaFX 2.0 user interfaces easier and more powerful from the Groovy language. I decided to reach out to the two main developers to see if they would kindly answer some questions relating to this project. Fortunately they agreed, and so here today we have the first interview on FX Experience. Enjoy!

Please introduce yourselves
Jim Clarke: I have been working with JavaFX for several years and am co-author of JavaFX-Developing Rich Internet Applications.
Dean Iverson: I work at the Virginia Tech Transportation Institute where I work with various rich client technologies.  I was an early adopter of JavaFX and a co-author of Pro JavaFX Platform.

(more…)

Welcome to another week of JavaFX links! :-) Let’s get right into it.

  • There was a new beta build of JavaFX 2.0 put out this week – b34 includes drag and drop support, as well as a Java to JavaScript bridge for WebView among the numerous bug fixes, API tweaks and performance improvements.
  • The Silicon Valley JavaFX Users Group is planning another meeting this week, but I’m not sure what the topic is. It is on Wednesday, July 13, 2011, 6:00 PM at the Oracle Conference Center.
  • Tom Schindl has released e(fx)clipse 0.0.2, which includes improved CSS editing support, as well as the start of better JavaFX integration into Eclipse in the form of JavaFX library specification in projects, a ‘New JavaFX Project’ wizard and JavaDoc integration.
  • jojorabbit4 has updated his ComboBox control to allow for more customisation.
  • Narayan Gopal Maharjan has put up a AutoFill TextBox with support for as-you-type filtering and auto-complete.
  • The GroovyFX project is continuing to get noticed – this week hideaki-t put up a custom browser using GroovyFX to demonstrate the power of GroovyFX and JavaFX.

I hope you all found something useful in this weeks link roundup. Keep up all the hard work folks, and I’ll be back in a weeks time to link to you all over again.

July already?! I know I say this often, but man, where does time go?! Also, happy Independence Day to the American readers out there (even though it’s technically not until tomorrow in your part of the world).

There are a heap of links, so lets jump right into it! :-)

That’s all for another week. I hope you all found something useful! Until next week – keep up the hard work folks :-)

For the past couple of years the industry has continued to follow Moore’s Law by shifting from CPU clock speed to increasing the number of cores and threads per core. Even cell phones are getting multiple cores these days! Taking advantage of all these cores and threads is one of the hallmarks of modern GUI platforms. But all this concurrency brings a multitude of problems to the application developer, not least of which is that writing multithreaded applications is hard!

In designing JavaFX 2.0, we of course needed to address both how the scene graph would behave in the presence of multiple threads, and how developers could effectively do work in background threads and keep the UI responsive. In short, the JavaFX scene graph, like all other mainstream GUI toolkits, is not thread-safe and must be accessed and manipulated from the UI thread (call the FX Application thread). Swing and AWT had the same basic policy (only work with Swing or AWT from the Event Dispatching Thread), as did SWT (only interact with SWT resources and components from the thread that owns them), as do all other major toolkits (JavaScript / HTML included).

The most common problem with this design is that developers who do not do work on background threads invariably create unresponsive applications, since this long lived (potentially blocking) code happens on the same thread that processes user events. That is, while your long lived operation is running, no mouse or key events are being processed, which leads to an application that appears to “hang”.

Further, actually writing well behaved background workers is difficult and error prone. Even if you create a Runnable and create a Thread and do your long-lived work in that background thread, at some point you need to communicate back to the UI, either with the result of the long-lived computation, or by communicating to a ProgressIndicator of some kind what the progress of this long-lived operation is. This is error prone, because you must be sure to communicate with the UI by putting events back onto the event queue (using Platform.runLater, the equivalent of Swing’s invokeLater).

Note: This article is a sneak peek at a new API which is coming in the next couple of weeks, but is not currently available in the Beta builds! There is a deprecated Task class in the beta builds which will be removed and replaced with the one detailed here.

Suppose we have a simple background thread which just counts from 0 to 1 million. Suppose I have a single ProgressBar, and that I need to update the progress of this ProgressBar as the counter runs. A naive implementation might look like this:

final ProgressBar bar = new ProgressBar();
new Thread(new Runnable() {
    @Override public void run() {
        for (int i=1; i<=1000000; i++) {
            final int counter = i;
            Platform.runLater(new Runnable() {
                @Override public void run() {
                    bar.setProgress(counter/1000000.0);
                }
            });
        }
    }
}).start();

This is a hideous hunk of code, a crime against nature (and programming in general). First, you’ll lose brain cells just looking at this double nesting of Runnables. Second, it is going to swamp the event queue with little Runnables — a million of them in fact. Clearly, we needed some API to make it easier to write background workers which then communicate back with the UI.

Java comes with a very complete set of concurrency libraries in the java.util.concurrent package. We wanted to leverage what was already defined in Java, but we needed to extend these APIs to take into account the FX Application thread and the constraints that GUI programmers are under. The javafx.concurrent package contains three core files: Worker, Task, and Service.

Before diving into the rather verbose description (taken from the proposed javadocs) for Worker, Task, and Service I wanted to cut to the chase and show some examples. The first key thing to mention, is that Worker is an interface that is implemented by both Task and Service, and which adds the sort of convenience API necessary for a background worker that is useful for communicating back with a UI. Second, Task extends from java.util.concurrent.FutureTask. This means that a Task can very cleanly fit into the concurrent libraries. As you may know, FutureTask implements Runnable, and can be passed to an Executor’s execute() method.

So real quick, here is the same example as above, but it suffers from none of the flaws exhibited in the naive implementation.

Task task = new Task<Void>() {
    @Override public Void run() {
        static final int max = 1000000;
        for (int i=1; i<=max; i++) {
            updateProgress(i, max);
        }
        return null;
    }
};
ProgressBar bar = new ProgressBar();
bar.progressProperty().bind(task.progressProperty());
new Thread(task).start();

In this example, I first create my Task. The task implementation just does its work, invoking the protected updateProgress method defined on Task, which ends up updating progress, totalWork, and workDone properties on the Task. I then create my ProgressBar and bind its progress property with the progress property of the Task. Then, since Task is a Runnable, I can just create a new Thread passing it the Task and then start the Thread.

Alternatively, I could create an Executor or ExecutorService (such as a ThreadPoolExecutorService) and execute the task using the ExecutorService.

(more…)