Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Anyone tried out JavaFX?

 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Frank Carver
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Frank Carver
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic