Window’s control button (minimize/maximize/close)

During development of custom desktop application sometimes you need to define own event handlers on these buttons. In SWING it is easy and well-documented task – in JavaFX it is also easy task, but it is not well-documented. Thus in this post I want to provide some information about it.

Minimize button

Let’s start from minimize button. In JavaFX for specifying own action on this button you need to define variable and “bind” it with iconified-property of state:

So using this structure you can esially handle minimize and restore window’s events.

Close button

In SWING documectation you’ll find a lot of information about processing close button’s event. Most of all standard needs are covered by setDefaultCloseOperation(int) method of JFrame class. Unfortunatly, you can not use this method in JavaFX: you can get window’s instance using JFXStage (see and call setDefaultCloseOperation with neccessary parameter, but it will not work.

So in JavaFX for defining own event handler you only need to define onClose of your stage instance:

This Article updated on May, 2016.