aspose file tools*
The moose likes Other Languages and the fly likes Anyone tried out JavaFX? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "Anyone tried out JavaFX?" Watch "Anyone tried out JavaFX?" New topic
Author

Anyone tried out JavaFX?

Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
It all looks very interesting, and the demos are very impressive, but so far I have not worked out how to run my own scripts.

The tutorial provided with the code has netbeans 5.5 as a prerequisite. I can't believe that a scripting system which is advertised as being so portable really needs netbeans to run.

I have tried using the "bat" files in the bin directory, but they always report that they can't find my file HelloWorld.fx, even though it's right here in the current directory.

Anyone managed to run JavaFX without netbeans, yet?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

I ran it with the Eclipse plugin. You have to feed the name of the script into the FXShell. So for example if you had a .fx file named HelloWorld, you might run it like the following from the command line:

java -cp path\to\fx\jar\file net.java.javafx.FXShell HelloWorld

HTH.


GenRocket - A Test Data Generation Platform
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Hmm. I'll try that method of invoking it. Thanks.

I tried the Eclipse plugin but it seems very "alpha". It gratuitously went and re-wrote the .classpath and .project files of all my other open java projects to refer to JavaFX. I had to manually revert changes to a dozen projects. Bleh.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
It still doesn't work, and I can't see why.

Here's a transcript:



It's clear that FXShell is running, and getting the filename parameter (it correctly adds the ".fx" to the end), but it insists that the file is not found.

HelloWorld.fx is copied directly from the tutorial:



I really don't understand why the FXShell is refusing to find my script.

Help!
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Aha! It works. I had a flashback to 10 years ago - a classpath problem

It was two problems:

1. I needed to add "." to the classpath, apparently it is attempting to load the supplied parameter as a classpath resource rather than from the filesystem or a remote URL.

2. When I finally got it to locate the source file, it also needed the other two jars in the classpath.

So, for anyone else who wants to try this, a better bat script might be:

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39543
    
  27

So that's what it looks like - CSS meets Java? This particular code snippet looks like just another notation for a regular Frame, though ... or is there something happening implicitly that would need to be done explicitly in J2SE?


Ping & DNS - updated with new look and Ping home screen widget
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
The quoted example is indeed just an alternative notation.

The cleverness comes when you mix behaviour into it. Here's another example from the tutorial:



This one demonstrates the use of the "bind" operation. It links (presumably using event listeners under the covers) both the frame title and the value of a text field to a value in a model object. The upshot is that when you run this (deceptively small) program, it allows you to enter a value in the text field, hit enter and it automatically updates the frame title. No other code needed.

That's beginning to get cool.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

The syntax is oddly similar to Groovy. Even their String manipulation.

Groovy:
var name = 'Gregg'
var message = "Hello ${name}"

JavaFX Script:
var name = 'Gregg'
var message = "Hello {name}"

And all the Swing stuff looks a lot like Groovy's SwingBuilder except for the binding elements. That is a nice feature of JavaFX scripting.
Juha Anon
Greenhorn

Joined: May 13, 2007
Posts: 5
Instructions for the first step using the Eclipse plugin -- from novice to novice.

Do a Hello World
=============
After installing the plugin, you won't see any change at all in the Eclipse interface except when you create the first JavaFX file. Create a new Java Project, and then Hello.fx in the source directory:

new | other... | javaFX | JavaFX File.

(The source directories are managed exactly like you would do with Java sources.)

When you add your first .fx-file in your Java project, the JavaFX plugin knows it should be a JavaFX-project, and adds the .jar files which are needed. It also knows that the run-configuration should now utilize the FXShell as main class.

The contents of Hello.fx may be something like this:

import javafx.ui.*;
import java.lang.System;

Frame {
content: Button {
text: "Press Me"
action: operation() {
System.out.println("You pressed me");
}
}
visible: true
}

You run it by right-clicking on the project (or the file you want to run) and add a new configuration for a �JavaFX Application�. It will have net.java.javafx.FXShell for Main class. You must add the name of the Hello.fx (or just the class name, �Hello�) to tell the shell what to run. (Otherwise, it compiles and run the empty set of classes without complaining: very annoying!)

The second step: run the demo application.
==============================
To run the demo application in Eclipe, you may use �demo.DemoLauncher� for argument to the FXShell.

You must also add the �demos� directory as a source directory along with �src�. You do that under Project | Properties | Java Build Path | Source. Otherwise, I didn't have to change anyting from what I got from the Subversion trunk (or the source download).

There's some Red in the Source: ignore it!
==============================
There is one spot in the code that the plugin complains about, but it worked anyway. Someone will remove that eventually... I guess.

This is the place causing it:

incompatible types: expected net.java.javafx.type.ValueList, found javafx.ui.canvas.Group
in new Group {transform: translate(30, 30), content: new ViewOutline {selected: true, view: widget, rectHeight: h, rectWidth: w}}
Tutorial Project/javafxpadJavaFXPad.fxline 980
Juha Anon
Greenhorn

Joined: May 13, 2007
Posts: 5
Eclipse is my favorite for serious work, but I would say that it's easier to start out from the demo application. There's no setup needed.

I downloaded openjfx-20070506220507.tar.gz and extracted it. Then just changed to the directory:
trunk/demos/demo

and run the command:
./demo.sh

It worked!

I haven't any classpath set. The only Java environment I have is that JAVA_HOME is set, and $JAVA_HOME/bin is in my path.

I'm running Java 1.6, but 1.5 is probably also good.

Run the tutorial, and start changing the scripts there. No need to recompile, or run! That's a small, but cute, development environment, I think.

-- Juha
Juha Anon
Greenhorn

Joined: May 13, 2007
Posts: 5
I see that I was unclear. When saying: You must add the name of the Hello.fx (or just the class name, �Hello�) to tell the shell what to run.

I ment: set Hello as argument (in the Arguments tag) to the FXShell.

-- Juha
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Anyone tried out JavaFX?
 
Similar Threads
Insider's Guide to Mixing Swing and JavaFX
JDBC and JavaFX
Compatibility with Windows
JavaFX v Flex
How can I include a JavaFX 2.0 application into a HTML page?