Periodic action

Timeline timeline = new Timeline(
        new KeyFrame(
                ae -> System.out.println("Periodic action")

FXML controller - constructor vs initialize method

The constructor is called first, then any @FXML annotated fields are populated, then initialize() is called. So the constructor does NOT have access to @FXML fields referring to components defined in the .fxml file, while initialize() does have access to them.

public class MyController implements Initializable {
    TableView<MyModel> tableView;

    public MyController() {
        tableView.getItems().addAll(getDataFromSource()); // results in NullPointerException, as tableView is null at this point.

    public void initialize(URL url, ResourceBundle rb) {
        tableView.getItems().addAll(getDataFromSource()); // Perfectly Ok here, as FXMLLoader already populated all @FXML annotated members.

Scene UserAgentStylesheet

Caspian is the theme that shipped as default in JavaFX 2.x.


Modena is the default theme for JavaFX 8.x.


High Contrast Themes

High contrast themes can be set with a command line option


The valid values are yellowOnBlack, whiteOnBlack, or blackOnWhite.

Virtual keyboard

Virtual keyboard can be enabled with below command line options. You must add these flags to the java VM, not to the application.


To customize the keyboard layout check /com/sun/javafx/scene/control/skin/caspian/fxvk.css in ${JRE/JDK_INSTALL}/jre/lib/ext/jfxrt.jar for the css fields influencing the keyboard.

To run command line options in Netbeans IDE, put VM option inside nbaction.xml

<runfx.args>-jar -Dcom.sun.javafx.isEmbedded=true -Dcom.sun.javafx.touch=true -Dcom.sun.javafx.virtualKeyboard=javafx ${}/${}.jar</runfx.args>

To have virtual keyboard for a textField use below code snippets. Use properties

TextField textField = new TextField();
textField.getProperties().put(FXVK.VK_TYPE_PROP_KEY, "numeric");

VK_TYPE_PROP_KEY can only get text, numeric, url, email values.

or use listener

textField.focusedProperty().addListener((ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue) -> {
    VirtualKeyboard keyboard = new VirtualKeyboard();
    if (newPropertyValue) {;
    } else {

public class VirtualKeyboard {
    public void show(TextField textField) {
        textField.getProperties().put(FXVK.VK_TYPE_PROP_KEY, "numeric");
    public void hide() {

To prevent opening virtual keyboard

textField.focusedProperty().addListener(new ChangeListener<Boolean>()
    public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue)
        if (newPropertyValue)

Display additional values in Pie Chart

Binding the pie chart data name

pieChartData.forEach(data ->
      data.getName(), " ", data.pieValueProperty(), " Tons"

If you want to avoid recomputing the total every time there’s a mouse event, you can create a DoubleBinding to store it:

DoubleBinding total = Bindings.createDoubleBinding(() ->, pieChartData);

If you have changing values and/or want to avoid displaying the values in the chart legend, you could modify the text label instead of changing the data names.

chart = new PieChart(pieChartData) {
  protected void layoutChartChildren(double top, double left, double contentWidth, double contentHeight) {
    if (getLabelsVisible()) {
      getData().forEach(d -> {
        Optional<Node> opTextNode = chart.lookupAll(".chart-pie-label").stream().filter(n -> n instanceof Text && ((Text) n).getText().contains(d.getName())).findAny();
        if (opTextNode.isPresent()) {
          ((Text) opTextNode.get()).setText(d.getName() + " " + d.getPieValue() + " Tons");
    super.layoutChartChildren(top, left, contentWidth, contentHeight);