Geertjan's Blog

  • July 2, 2012

Advanced Experiments with JavaScript, CSS, HTML, JavaFX, and Java

Geertjan Wielenga
Product Manager

Once you're embedding JavaScript, CSS, and HTML into your Java desktop application, via the JavaFX browser, a whole range of new possibilities open up to you.

For example, here's an impressive page on-line, notice that you can drag items and drop them in new places:


The source code of the above is provided too, so you can drop the various files directly into your NetBeans module and use the JavaFX WebEngine to load the HTML page into the JavaFX browser. Once the JavaFX browser is in a NetBeans TopComponent, you'll have the start of an off-line news composer, something like this:

WebView view = new WebView();
view.setMinSize(widthDouble, heightDouble);
view.setPrefSize(widthDouble, heightDouble);
webengine = view.getEngine();
URL url = getClass().getResource("index.html");
new ChangeListener() {
public void changed(ObservableValue ov, State oldState, State newState) {
if (newState == State.SUCCEEDED) {
Document document = (Document) webengine.executeScript("document");
NodeList list = document.getElementById("columns").getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
EventTarget et = (EventTarget) list.item(i);
et.addEventListener("click", new EventListener() {
public void handleEvent(Event evt) {
instanceContent.add(new Date());
}, true);

The above is the code showing how, whenever a news item is clicked, the current date can be published into the Lookup. As you can see, I have a viewer component listening to the Lookup for dates.

Join the discussion

Comments ( 2 )
  • guest Tuesday, July 3, 2012


    when i opened site at http://nettuts.s3.amazonaws.com/127_iNETTUTS/demo/index.html

    my browser didn't asked me for any java plugin...

    can you tell me is it possible to create a website in javafx without any pre-requisites,i mean that it doesn't prompt user for any java plugin and still works perfect

  • guest Wednesday, July 4, 2012

    Looks great

    Where is the complete source code for that please ?


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.