Tips & Tricks

JavaFX Tip 5: Be Observable

Even in this time of total NSA surveillance it is still a good idea to implement your JavaFX controls with observability in mind. This is easy to achieve in JavaFX especially compared to Swing. The Old Days Coming from Swing I was used to spending a lot of energy and time on making custom controls observable. It usually required adding methods to add and remove listeners of a certain type. This listener type was a new interface, the single method of that interface accepted a new event object. To send this event object the control had to "fire" it [...]

By |2021-02-18T13:42:31+01:00July 10th, 2014|FlexGantt, Java, JavaFX, Tips & Tricks|3 Comments

JavaFX Tip 4: Have the Final Word

When developing custom controls for JavaFX I would highly recommend to follow in the footsteps of  the core JavaFX controls and to make the API of your controls as final as possible and to put the "final" keyword in front of all your method declarations. Example In FlexGanttFX I have a lot of code that looks like this: public final Activity getActivityAt(double x, double y) { ... } public final Row getRowAt(double y) { ... } public final void setShowLinks(boolean show) { ... }   Why? When you design a control you have a specific behaviour of the control in [...]

By |2021-02-18T13:42:31+01:00July 9th, 2014|FlexGantt, Java, JavaFX, Tips & Tricks|8 Comments

JavaFX Tip 3: Use Callback Interface

As a UI framework developer it is part of my job to provide ways to customize the appearance and behavior of my controls. In many cases this is done by allowing the framework user to register a factory on a control. In the past I would have created a factory interface for this and provided one or more default implementations within the framework. These things are done differently in JavaFX and I have started to embrace it for my own work. JavaFX uses a generic interface called javafx.util.Callback wherever a piece of code is needed that produces a result (R) for a given parameter [...]

By |2021-02-18T13:42:31+01:00April 15th, 2014|JavaFX, Tips & Tricks|2 Comments

JavaFX Tip 2: Sharp Drawing with Canvas API

When I initially started out working with the Canvas API I noticed that the results of my rendering code were somewhat blurry and even worse, inconsistent. Some lines were blurry, others sharp. Coming from Swing it took me some time to realize that this was caused by the coordinate system of JavaFX, which allows for double precision rendering. To solve this problem all that is needed is to use coordinates "in the middle". So in my code you now find a lot of methods called snapXYZ() (similar methods can be found in the JavaFX code itself), which first casts [...]

By |2021-02-18T13:42:31+01:00April 10th, 2014|Java, JavaFX, Tips & Tricks|5 Comments

JavaFX Tip 1: Resizable Canvas

While working on FlexGanttFX I had to deal a lot with the JavaFX Canvas node. I am using it to render activities on a timeline. Each row in the Gantt chart is a Canvas node. The user has the option to resize each row individually. So I had to figure out the best way to resize a canvas, which out-of-the-box is not resizable. The listing below shows how this can be accomplished. The main steps needed are: Create a subclass of Canvas. Override the isResizable() method and return true. Override the prefWidth() and prefHeight() methods. Return the values of Canvas.getWidth() and Canvas.getHeight(). [...]

By |2021-02-18T13:42:31+01:00April 10th, 2014|Java, JavaFX, Tips & Tricks|18 Comments