Toni Epple works as a consultant for Eppleton (http://www.eppleton.de) in Munich, Germany. In his spare time he's an active member of the Open Source community as a community leader for JavaTools community (http://community.java.net/javatools/), moderator of the XING NetBeans User Group (http://www.xing.com/group-20148.82db20), founder of the NetBeans User Group Munich (http://tinyurl.com/5b8tuu), member of the NetBeans Dream Team (http://wiki.netbeans.org/NBDTCurrentMembers) and blogger (http://www.eppleton.de/blog). Toni is a DZone MVB and is not an employee of DZone and has posted 51 posts at DZone. You can read more from them at their website. View Full User Profile

NetBeans IDE 7.1 Review: JavaFX Support

01.16.2012
| 17706 views |
  • submit to reddit

Last year, with the release of version 2.0, JavaFX finally started to gain attention at the big conferences and there seemed for the first time to be a shift in developer perception now that Oracle addressed the issues that kept Java developers from using this new UI technology.

There's the following issues that have now been resolved:


So, there's basically no excuse anymore not to use it ;-), and with competitors Flash and Silverlight losing support from its creators, it was high time to give developers the tooling to play with JavaFX.

January 5th, 2012, the NetBeans Team released version 7.1 of the popular IDE. The most significant changes are support for JavaFX 2.0, a UI Debugger for JavaFX and Swing and a new Batch-Refactoring tool for bulk changes in Java projects. Besides that many components have been updated, e.g. Java EE support, PHP projects and there have been some improvements in supported Code Versioning Systems. In this article we'll have a closer look at the JavaFX support.

 

Image 1:A JavaFX Demo Application shipped with NetBeans


JavaFX 2.0 Project Types

After dumping JavaFX Script (which lives on outside Oracle and has broadened its scope as project Visage) and moving to plain Java and FXML all existing tools were rendered useless. The support for JavaFX had to be recreated from scratch based on Java Projects. After years of refactoring the JavaFX support over and over, it must have been a relief for the NetBeans team that there'll be no more weekly random language changes to the JavaFX Script Spec. Still it's a bit sad that so much work had to be wasted that could have gone into other parts of the IDE.  And some people still feel that the Script language was actually not a bad idea at all.

 

NetBeans 7.1 adds three ANT-based project types for JavaFX: "JavaFX Application", "JavaFX Preloader", and "JavaFX FXML Application". JavaFX Application basically is a standard ANT project with enabled JavaFX capabilities. During project creation it will check for a JavaFX-enabled JDK, and if there isn't one registered, it will help you add JavaFX support to a standard JDK. The project enables you to build, run and debug your application. The only difference to this in a JavaFX FXML Application is the generated code you can use to start with. In the latter case the code for loading the UI from an example FXML file will be generated. There's still nothing that keeps you from using FXML in a standard JavaFX Application.

A JavaFX Preloader project creates a Preloader, a small application that can run before the actual application during the applications startup process. It's especially useful in JNLP-based deployments and can be used to show progress (splash screen). The project will create the code for a simple Preloader Window containing a ProgressBar:

 

Using it as a splash screen for a JavaFX Application is simple. Right-click your JavaFX Application project and choose "Properties". In the Properties Dialog switch to the "Run" Tab. Using the "Browse" Button next to the disabled Preloader section, you can then select a JAR-File or a NetBeans project to register the Preloader. At the next start, your application will display the Preloader. There's a nice tutorial describing how you can create and register your Preloader using NetBeans in more detail.

FXML

NetBeans 7.1 adds support for FXML, the new XML Format for specifying the UI. When creating a new FXML-Template, either by creating the project as described above, or by creating it using the "New File" Wizard, the IDE will automatically create controller class for you. That's nice, because even though Controllers are optional, it's good architecture to use them in order to separate behavior from the design and encapsulate it in a dedicated class.

 

One of the problems of the FXML format is that unfortunately there's no schema/DTD. As a result the default XML-support will not be able to give you any help like Code-completion, etc.. So while NetBeans supports editing FXML files, it doesn't provide help beyond checking the correctness of your opening and closing tags. 

Nevertheless I'd expect a graphical tool for editing FXML files anyway, and I assume that it's on the TODO list for the next release. Until then I personally don't use FXML too much, because I feel that XML is simply too verbose and the need of opening and closing tags to define an object hierarchy are getting in the flow of programming. The Eclipse Project for supporting JavaFX development e(FX)clipse has even invented their own DSL fxgraph, which is later converted to FXML in order to work around these problems. A smart idea and a better alternative for hand-coding UIs declaratively.

Debugging UI Snapshots

Other than that the JavaFX support works very nicely and it adds one extremely cool feature: graphical debugging. During a debugging session you now can take UI snapshots, that will show up in the IDE. In the screenshot you can now select the individual components and explore their properties using the Properties Window. You can explore the component hierarchy in the Navigator and there's a new "Events" Tab in the Output Area listing Listeners attached to the controls and even allowing to attach logging listeners. The events window is a bit hard to find though. It can be opened from the context menu of a component in the Navigator. That new tool is very cool and helpful, but so far I only got this feature to work with Swing applications on my Mac, not for JavaFX; maybe a bug of the Beta OS X JavaFX version.

 

Styling applications with CSS

My favorite feature of JavaFX 2.0 is CSS support for styling. NetBeans 7.1 now supports that by adding CSS3 support, so controls can easily be customized using this approach. For more details have a look at my recent article on DZone showing an example of this technique. Unfortunately the CSS-support does not yet provide code completion for JavaFX-specific properties, or at least I wasn't able to invoke it. Also the CSS-Stylebuilder and the preview seem to only work with the default (HTML) properties. So there's still room for improvement here.

Samples and other stuff

NetBeans shipped with more than 30 sample JavaFX applications demonstrating different aspects of JavaFX. They cover everything from Charts, FXML, Transitions, Animation, Key- and MouseEvents, Media, etc. and are a great resource for learning.

 

When it comes to deployment, all proposed deployment models, Applets, Desktop and Webstart are now supported by the IDE and there's support for Preloaders that make it possible to customize and improve the loading experience of a JavaFX application, another thing developers have been asking for a long time. You can configure these settings very comfortably in the Projects Properties.

I used the JavaFX support in NetBeans IDE quite a bit in the past weeks in the NetBeans IDE Release Candidates, and it's definitely usable and helpful. So I'm hoping for some graphical tools that make it easy to define UIs either as part of the IDE or as accompanying tools.

Published at DZone with permission of Toni Epple, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Alessandro Polverini replied on Mon, 2012/01/16 - 4:12pm

> So, there's basically no excuse anymore not to use it ;-)

Actually, I find the lack of linux support a completely blocking issue...

Witold Szczerba replied on Mon, 2012/01/16 - 7:38pm in response to: Alessandro Polverini

Actually, I find the lack of linux support a completely blocking issue...

True. Is this <rethorical mode on> really a core-Java thing<rethorical mode off>?

I am wondering what is this all about? JavaFX seems to be a HTML/CSS clone. Do we really need this anymore? Since there is AngularJS framework, which in few words can be summarized like this: 

AngularJS is what HTML would have been, had it been designed for applications.

The bottom line is - you can run it almost anywhere, the only thing one needs is a web browser. You can also embed a browser widget in a standalone PC application (JavaFX provides that), so web browser users can still use it without installing anything on any OS (Windows, Mac, Linux, Android, iPad, etc...) and for some specific operations requiring extra integraton - there can be also a native application or browser plugin (like signed Java Applet, Flash, etc.) provided. That would be some something like:

Write once, adapt anywhere :)

Because GUI is like 95% of typical application, so for different environments one has to adapt only 5%.

Regards,
Witold Szczerba

Jirka X1 replied on Tue, 2012/01/17 - 3:09am in response to: Alessandro Polverini

Exactly. And according to the roadmap there will be no support for a year.

Toni Epple replied on Tue, 2012/01/17 - 3:56am in response to: Alessandro Polverini

Linux support will be available in the second half of 2012, and so far Oracle has proved very trustworthy when it comes to roadmaps.

Toni Epple replied on Tue, 2012/01/17 - 4:13am in response to: Witold Szczerba

@Witold: I think their correct claim is: "What HTML would have been
had it been designed for web apps" which is slightly different.

JavaFX can be used on the Desktop, in Applets and using Webstarts. One of the things I'm personally specifically interested in is the use on the desktop.

It's arguable if/how JavaFX will compete with HTML5, but I mainly create desktop applications. I use powerful application platforms like Eclipse RCP or NetBeans Platform and use JavaFX to spice them up with charts, animations, media, I can even integrate a web browser. So I can write cooler applications without having to switch to a different framework. That's a big gain, and that alone makes JavaFX a win for me.

 

 

Witold Szczerba replied on Tue, 2012/01/17 - 11:05am in response to: Toni Epple

@Witold: I think their correct claim is: "What HTML would have been had it been designed for web apps" which is slightly different. 

I am not sure anymore. How do you define web application? Is that just because it works in a web browser? Once you create an OS-specific application which embeds HTML pane, is it still a web app? Who can tell? What is the difference?

For me, the only difference is that such an application can be ported easily, because almost any OS can provide a runtime environment for HTML/CSS and JS. And as I said before, in most cases it is more than 90% of all the client-side code base: forms, rich widgets, charts, media, animations... (almost) everything is supported. Additional benefit, in case one does not understand HTML/CSS, is that it is very easy to find someone who does know that. UI experts can "draw" entire UI in blink of an eye. Developers are then just wiring it with backend and adding extra presentation logic.

Now your customer would like the application to be used on iPads, Android tablets, Android note/netbooks or Windows 8 ARM or what-else. With JavaFX you can only pray Oracle will do something or you can start writing brand new front-end from scratch. This is not the case when using HTML/CSS + JS. All you would have to do would be to port those few features which required extra integration. And you can do it at little cost. The only missing thing was the lack of solutins like AngularJS.

I am not saying you are wrong in any way. I am not saying JavaFX is wrong. I just wanted to make a note there is an alternative and more OS independent way to build applications. Exactly same thing applies to Flash, Silverlight, plain old Swing/SWT or .Net.

Regards,
Witold Szczerba

Tim Boudreau replied on Tue, 2012/01/17 - 11:03am

Ah, the inescapable XML fetish.

Toni Epple replied on Tue, 2012/01/17 - 1:19pm in response to: Tim Boudreau

@Tim: Yes, everybody has to pay the the angle bracket tax :-). 

Rob Ratcliff replied on Wed, 2012/01/18 - 10:48am in response to: Witold Szczerba

Since the decline of J2ME, you're right about HTML5/JS being the only current cross-platform solution on mobile platforms right now, unfortunately, but the problem is that its basically the V'ger of rich client applications. Do you really want to be a Javascript programmer given the lack of type-safety, performance, library support and capabilities, not to mention global variable, ad-hoc object structure manipulation, etc?

There is no comparison to what can be currently done with JavaFX and the Java Plug-in as seen in this demo1 (fast forward to 50 minutes or so) and this demo2

Like you, I hope there is a viable plan to get JavaFX onto mobile platforms!

Vger

V'ger - What should be the symbol for the current trend in web applications!

Witold Szczerba replied on Fri, 2012/01/20 - 3:44am in response to: Rob Ratcliff

Since the decline of J2ME, you're right about HTML5/JS being the only current cross-platform solution on mobile platforms right now, unfortunately, but the problem is that its basically the V'ger of rich client applications.

 It is not the only cross-platform solution on mobiles, but it is cross-platform solution on (almost) everything, including desktops.

 Do you really want to be a Javascript programmer given the lack of type-safety, performance, library support and capabilities, not to mention global variable, ad-hoc object structure manipulation, etc?

As a Java programmer, I was very sceptical, but well, I do not mind any more. JavaScript is much better when you start actually using and mastering it than you think it is. As to the lack of type-safety - many languages are not type-safe and are widely used even for complicated, server side stuff (Google App Engine was first available for Python environment). Lack of JS library support? Come on...

I was referencing AngularJS twice in this thread and I am mentioning it again. This kind of thing let you write clean, wisely structured and testable code (unit tests, integration and e2e). Believe me - this is not kind of JavaScript mess most of us are used to (script here, script there, workaround everywhere).

Last, but not least, I do believe JavaFX is not going to be a standard ever. No one but Oracle will have full (or almost full) control over it. Whatever happens - JavaFX developers are condemned to wait for Oracle move. Once Oracle looses its business in it - you can pack your toys and start from scratch. 

Toni Epple replied on Fri, 2012/02/10 - 8:59am in response to: Witold Szczerba

Last, but not least, I do believe JavaFX is not going to be a standard ever.  No one but Oracle will have full (or almost full) control over it. Whatever happens - JavaFX developers are condemned to wait for Oracle move. 

And your believe is backed by what? Like Angular JS, JavaFX it's an Open Source project ( http://openjdk.java.net/projects/openjfx/ ), and the plan is to even make it part of Java 9 SDK.

Once Oracle looses its business in it - you can pack your toys and start from scratch. 

Now that's an interesting thought from someone who in the same breath is promoting Angular JS, a technology backed by Google :-). 

Remember Google Wave? Here are some newer examples of abandoned Google projects: http://en.wikinoticia.com/Technology/general-technology/106999-the-3-products-that-google-abandoned-in-2012 

 

 

Toni Epple replied on Fri, 2012/02/10 - 8:57am in response to: Jirka X1

Just in case you want to try it out, here's the linux developer preview:

http://www.oracle.com/technetwork/java/javafx/downloads/devpreview-1429449.html

Matt Coleman replied on Tue, 2012/04/17 - 12:40am

 now this is so fantastic!!i cant wait to have this a go

graphic design buffalo

Sheraz Butt replied on Sun, 2012/05/20 - 11:05am

 now this is so fantastic!!i cant delay to have this a go www.trendsandgadgets.net

Sheraz Butt replied on Tue, 2012/06/19 - 7:54am

 now this is so fantastic!!i cant delay to have this a go www.sharksteammopreviews.net

Sheraz Butt replied on Sat, 2012/10/13 - 3:08am

Thanks I like it keep it up ... bespoke dress Shirts

Uchenna Ani-Okoye replied on Wed, 2014/05/07 - 3:40pm

I'm much more familiar with JavaScript, having done some coding in it. However, JavaFX does look interesting. I'd say it's not getting that much of a look in, since it's popularity is fairly minimal.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.