To make the main Java FX window completely transparent, you only have to set the StageStyle.TRANSPARENT and the Scene#setFill(null):
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class TransparentStage extends Application {
@Override
public void start(Stage stage) {
stage.initStyle(StageStyle.TRANSPARENT);
Text text = new Text("Transparent!");
text.setFont(new Font(40));
VBox box = new VBox();
box.getChildren().add(text);
final Scene scene = new Scene(box,300, 250);
scene.setFill(null);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
If you run "java -jar killer-app.jar" on a machine where JavaFX SDK was installed with a simple "unzip" (like a Mac), you will get the following error:
Unable to read ../rt/lib/jfxrt.jar
Unable to read ../../../../rt/lib/jfxrt.jar
Unable to read ../../sdk/rt/lib/jfxrt.jar
Unable to read ../../../artifacts/sdk/rt/lib/jfxrt.jar
Because the Java FX launcher does not know where to find the runtime, it falls back to the default location.
To solve this problem, just pass the system property: javafx.runtime.path with the JavaFX SDK location at start:
java -Djavafx.runtime.path=[THE UNZIPPED JAVA FX SDK]/rt -jar killer-app.jar
Java FX 2 is Java. To build a Java FX application you only need an additional JAR: jfxrt.jar which contains the Java FX UI classes. The JAR comes with Java FX SDK, but is not included in the public maven repository. You can point to the Java FX SDK installation with Maven's system scope dependency:
Synthetica V2.13 and SyntheticaAddons V1.5 L&Fs for Swing are released. See also NetBeans RCP with Synthetica L&F.
Some screenshots with NetBeans 7 IDE with Synthetica L&F:
A table control was missed in JavaFX 1.3. JavaFX 2 comes with a new table component:
import javafx.application.Application;
import javafx.application.Launcher;
import javafx.collections.FXCollections;
import javafx.collections.Sequence;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.table.TableColumn;
import javafx.scene.control.table.TableView;
import javafx.scene.control.table.model.SequenceTableModel;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start() {
Stage stage = new Stage();
stage.setTitle("Hello Table");
final Group root = new Group();
Scene scene = new Scene(root);
stage.setScene(scene);
Sequence children = root.getChildren();
children.add(getTableView());
stage.setVisible(true);
}
//TableView is a node...
public static Node getTableView() {
Sequence data = fetchDataFromServer();
TableView tableView = new TableView();
SequenceTableModel tableModel = new SequenceTableModel(data);
tableView.setModel(tableModel);
TableColumn[] columns = buildColumns(data);
tableView.getColumns().addAll(columns);
return tableView;
}
//sequence is an Observable java.util.List. It could come directly from e.g. JPA EntityManager.
public static Sequence fetchDataFromServer() {
return FXCollections.sequence(
new Person("Duke", "Java"),
new Person("DukeFX", "JavaFX"));
}
public static TableColumn[] buildColumns(final Sequence data) {
TableColumn firstNameCol = new TableColumn();
firstNameCol.setText("First");
firstNameCol.setGetCellData(new TableColumn.GetCellData() {
@Override
public Object get(long row, int col) {
return data.get((int) row).getFirstName();
}
});
TableColumn lastNameCol = new TableColumn();
lastNameCol.setText("Last");
lastNameCol.setGetCellData(new TableColumn.GetCellData() {
@Override
public Object get(long row, int col) {
return data.get((int) row).getLastName();
}
});
return new TableColumn[]{firstNameCol, lastNameCol};
}
public static void main(String[] args) {
Launcher.launch(Main.class, args);
}
}
public class Person {
private String firstName;
private String lastName;
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
//with getters.
}
A similar example comes with JavaFX 2 already. I just decomposed the origin example in several methods to see what happens behind the scenes.
Java FX 2 application can be compiled having jfxrt.jar in the classpath and launched like any other Java application: java -cp javafx-sdk2.0-ea/rt/jfxrt.jar com.abien.table.Main
Even in the case of the preview the startup performance is <1 sec and significantly faster, than 1.X version.
This post is based on Java FX 2 Early Access - the API and runtime can change any time.
Sees official JavaFX roadmap for more details.
Number of posts: 2419
Number of comments: 6163
Yesterday's hits: 18790
Today's hits: 11279
Post reads / hour: 773
Top posts: