Tips & Tricks

Shadow Fields vs. Property Accessor Interface

Carl Dea recently followed up on a blog post of mine called Save Memory! Use Shadow Fields for Properties. In his blog he suggested the use of an interface called "Property Accessor" to eliminate the heavy use of boilerplate code that is needed in order to use  shadow fields. Carl also mentioned that he hasn't tested his approach with a lot of data and that he or some reader might follow up with a performance comparison. So here it comes. I wrote a small test application that implements the three strategies that Carl mentions in his post: standard properties that are instantiated [...]

By |2021-02-18T13:42:26+01:00April 4th, 2016|Java, JavaFX, Tips & Tricks|2 Comments

JavaFX Tip 23: Save Memory! Shadow Fields for Properties.

Properties and property bindings introduced in Java 8 are extremely useful programming concepts. They are especially useful when you are developing user interfaces. In fact they are so useful that developers have fallen victim to the idea that everything should be a property instead of a primitive. Unfortunately they easily forget that properties such as SimpleLongProperty are much bigger objects than standard types such as Long. And of course they are much bigger than primitive data types such as long. In one of my current projects pretty much every model object used by the client is composed of properties. For many of these [...]

By |2021-02-18T13:42:26+01:00March 30th, 2016|Java, JavaFX, Tips & Tricks|21 Comments

JavaFX Tip 22: Autosize (Tree) Table Columns

One of the first things mentioned as a "missing feature" in the JavaFX "Missing Features Survey" was the ability to auto-resize columns in tables / tree tables. It is correct that there is no public API for it, but when you pay close attention then you will notice that there must be code for doing this somewhere inside JavaFX, because the user can auto-resize a column by double clicking on the divider line between the column and the next column to the right. But like most people I felt that this was not good enough for my code. I wanted [...]

By |2021-02-18T13:42:28+01:00December 10th, 2015|JavaFX, Tips & Tricks|2 Comments

JavaFX Tip 21: Animate!

When developers try to sell the switch from Swing to JavaFX to their superiors they often say that the user interfaces will look better and more modern. However, to really deliver on this promise I believe that one can not just rely on the improved look and feel of the built-in controls of JavaFX but that some extra effort has to be made to make the UI really stand out and to make everyone say "yeah, this is really an improvement". One of the things that can be done to spice up the UI is to animate some of its [...]

By |2021-02-18T13:42:29+01:00June 18th, 2015|CalendarFX, JavaFX, Tips & Tricks|1 Comment

JavaFX Tip 20: A lot to show? Use Canvas!

There seem to be two kinds of JavaFX applications: the first one is using a scene graph with nodes and CSS styling, and the second one is using a single canvas. However, it is perfectly legal to mix these two approaches. Especially when your application has to show a lot of detailed information where you would easily end up creating thousands and thousands of nodes. Even though the overall performance of JavaFX is fantastic you will most likely bring your system down to its knees when styling is required for all of these nodes (especially when styling is required over and over again because of [...]

By |2021-02-18T13:42:29+01:00June 16th, 2015|Java, JavaFX, Tips & Tricks|5 Comments

JavaFX Tip 19: Watch Your Skin

A common mistake that I do over and over again is that I put certain code into the skin class of a custom control while it should have been inside the control class itself. I just noticed this again when going through the list of bugs filed for the PopOver control of ControlsFX. I contributed this control, hence I feel responsible for fixing those bugs (when time permits). One of the issues mentioned that it is hard or impossible to change the styling of the PopOver control. After some investigation I realised that I am adding a stylesheet to the [...]

By |2016-07-15T15:38:36+02:00June 5th, 2015|Java, JavaFX, Tips & Tricks|4 Comments

JavaFX Tip 18: Path Clipping

I recently noticed that the PopOver control, which I committed to the ControlsFX project, does not properly clip its content. It became obvious when I was working on the accordion popover for the FlexCalendarFX framework. Whenever the last titled pane was expanded the bottom corners were no longer rounded but square. After placing a red rectangle as content to the titled pane it became clear to me that I forgot to add clipping. The following picture shows the problem. Normally clipping in JavaFX is quite easy. All it takes is an additional node and a call to setClip(node). However, normally [...]

By |2021-02-18T13:42:29+01:00February 18th, 2015|ControlsFX, Java, JavaFX, Tips & Tricks|3 Comments

JavaFX Tip 17: Animated Workbench Layout with AnchorPane

I recently had to implement a layout for an application where the menu area and the status area could be hidden or shown with a slide-in / slide-out animation based on whether the user was logged in or not. The following video shows the the layout in action: [youtube=http://youtu.be/cKXFG4pAoys] Update: a new video shows even better how the panes slide in and out. [youtube=http://youtu.be/qdplhq1KJLs] In the past I probably would have implemented this kind of behavior with a custom control and custom layout code (as in "override layoutChildren() method in skin"). But this time my setup was different because I [...]

By |2021-02-18T13:42:29+01:00February 6th, 2015|Java, JavaFX, Tips & Tricks|4 Comments

JavaFX Tip 16: Undecorated & Transparent Stages

Last week I had some fun playing around with the "Undecorator" classes from Arnaud Nouard. I was looking into it because I was thinking about writing a JavaFX showcase application that integrates / lists the various resources available for JavaFX development. My goal for this application is to come up with something very slick and sexy, something unconventional, something with a lot of animations and cool effects. So I started by taking over full control of the appearance of the stage by using "Undecorator". With the apperance of Yosemite transparent stages / windows are the way to go so I wanted [...]

By |2021-02-18T13:42:30+01:00November 17th, 2014|JavaFX, Tips & Tricks|8 Comments

JavaFX Tip 15: ListView Autoscrolling

I recently had to implement autoscrolling functionality for FlexGanttFX and thought that my solution might be useful for others. You find the basic concepts of it in the listing below. The main idea is that a background thread is used to adjust the pixel location of the virtual flow node used by the list view. The thread starts when a drag over is detected "close" to the top or bottom edges. "Close" is defined by a proximity variable. This code can obviously be improved by using a property for the proximity value and the types "Task" and "Service" for the [...]

By |2021-02-18T13:42:30+01:00October 31st, 2014|JavaFX, Tips & Tricks|5 Comments