edu.makery.ch

Education in the Making.

Category: JavaFX - show all

JavaFX Deployment on Mac OS

Eskil, one of my students, provided me with information about how to deploy the JavaFX AddressApp on Mac OS.

I’ve updated the AddressApp Tutorial Part VII with instructions about JavaFX deployment for Mac.

To see how the end result will look like you can download it as a Mac OS dmg drag-and-drop installer: AddressApp.dmg

Thank you Eskil for providing this!

JavaFX Scene Builder and E(fx)clipse Updates

I’m excited about the quick reaction to bug reports by the JavaFX developers at Oracle! I’ve reported an (annoying) Scene Builder bug at the end of November and it was already fixed in a new Scene Builder version in January.

Scene Builder Update

The Scene Builder bug forced us to delete and then reselect the controller class every time we reopened a fxml file in Scene Builder. This is fixed in Scene Builder 1.1 beta 17 and above. So I recommend you update to the newest version:

JavaFX Date Picker

As JavaFX 2.2 doesn’t contain a Calendar control we would have to create our own to provide a convenient way to enter a date. Fortunately, Christian Schudt has created a very nice DatePicker that we can use:

JavaFX Snapshot as PNG Image

JavaFX 2.2 and above provides a convenient snapshot feature. It takes a snapshot of any node or scene.

The following method saves the barChart node as a png image:

1
2
3
4
5
6
7
8
9
10
11
12
13
@FXML
public void saveAsPng() {
  WritableImage image = barChart.snapshot(new SnapshotParameters(), null);
  
  // TODO: probably use a file chooser here
  File file = new File("chart.png");
  
    try {
        ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);
    } catch (IOException e) {
      // TODO: handle exception here
    }
}

Note: You could test this code with our AddressApp example (see download at the end of AddressApp Tutorial Part VII). Just add the saveAsPng() method to the BirthdayStatisticsController class and call the method through some action (e.g. a new button).

JavaFX Event Handlers and Change Listeners

Very often in JavaFX we have to react to user events: The user clicks a button, presses a key, moves the mouse, etc. This post describes how to handle such events.

We’ll try to do as much event handling with Scene Builder and fxml as possible. For some events we’ll add event handling in the Java code of the controller.

Our example covers some of the most used events on common JavaFX 2 controls:

JavaFX TableView Cell Renderer

In this post I will show how to customize the rendering of a JavaFX 2 TableView. The Birthday column in the screenshot below is a formatted Calendar object. Depending on the year, the text color is changed.

JavaFX TableView Filter

The JavaFX 2 TableView lacks the ability for filtering. The intention before JavaFX 2.0 shipped was to include a FilteredList that would wrap an ObservableList (see Oracle forum Filter rows on TableView). Unfortunately, the filtering was removed again. It will appear in JavaFX 8 which won’t be released before late 2013.

In this post I will explain how we can manually do row filtering in JavaFX 2.

New Java and JavaFX Learn Pages

I created two new pages to structure content on this website. The pages will guide you through the learning resources about Java and JavaFX:

JavaFX 2 Tutorial Part VII - Deployment With E(fx)clipse

Updated Feb 11th, 2013: New instructions for Deployment on Mac OS. Thank you Eskil for providing me with this information!

I thought I’d write one last part of this tutorial series to show how to deploy (i.e. package and publish) the AddressApp.

Download example AddressApp as

Topics in Part VII

  • Deploying our JavaFX application as Native Package with e(fx)clipse