Java Method Reference Evaluation

Along with lambda expressions, Java SE 8 introduced method references as a shorthand notation. These are mostly used to reference static methods (e.g. Double::toString) or constructors (e.g. String[]::new), and these uses are straightforward. However, method references to instance methods can yield results that differ from lambda expressions in surprising ways. This is because the invocation … Continue reading “Java Method Reference Evaluation”


JavaFX provides some dedicated system properties to customize its behavior. Usually these are specified as command-line flags on the java/javaw invocation, using the syntax “java -Dname=value” followed by the JavaFX application path. I’ve previously noted two especially useful ones, as of Java SE 8u66-77: -Dprism.order=sw enables software rendering, even if JavaFX thinks hardware acceleration is … Continue reading “JavaFX and JAVA_TOOL_OPTIONS”

Loop Closures in Java & C#

The lambda expressions introduced in Java 8 can capture, or “close over”, any local variable that’s within scope and effectively final (Java 8 Language Specification §15.27.2, §4.12.4). Interestingly, this includes the loop variables of enhanced for loops, or for-each loops as I prefer to call them. Cay Horstmann mentions this very useful but non-obvious fact … Continue reading “Loop Closures in Java & C#”

Glyph Positioning in JFreeSVG & OrsonPDF

Object Refinery Ltd. makes two small but extremely useful Java libraries for producing vector graphics. JFreeSVG (free & commercial) supports Scalable Vector Graphics (SVG) and HTML5 Canvas output, and OrsonPDF (commercial with free demo) supports Adobe PDF output. Each provides a custom implementation of java.awt.Graphics2D, the 2D drawing surface for the Java AWT graphics library. … Continue reading “Glyph Positioning in JFreeSVG & OrsonPDF”

ListView Text Alignment

The ListView class of JavaFX 8 shows one item per line – one String in the simplest case. What if you want to visually separate individual string fragments (words, numbers)? You could use a TableView with multiple columns, but that may not be appropriate for your data. Or you could insert tab characters (“\t”) into … Continue reading “ListView Text Alignment”

Simulating Platform.runAndWait

Every JavaFX application maintains one single JavaFX application thread running the application’s event queue, much like Swing’s event dispatch thread. System-generated events such as mouse clicks are automatically inserted into the event queue. JavaFX also provides the method Platform.runLater to programmatically enqueue an arbitrary Runnable function object. You might occasionally wish to call runLater from … Continue reading “Simulating Platform.runAndWait”

JavaFX Text Icons as Images & Files

There are plenty of high-quality icon fonts for scalable user interfaces, and drawing them directly as Text into JavaFX UIs is simple. But what if you need the icon as an Image or a disk file? That’s not hard to achieve, either, but there are some non-obvious steps and many Java APIs to navigate. So … Continue reading “JavaFX Text Icons as Images & Files”

JavaFX ListView Sizing

JavaFX supports automatic self-adjusting layout that resizes controls along with the containing window, but this may require some non-obvious changes to the controls’ default properties. The problem I recently ran into was automatically resizing a ListView within a VBox. This article describes the undesirable default behavior and its correction, based on JavaFX 2.2 in JDK … Continue reading “JavaFX ListView Sizing”

Jumping out of Java finally

The definition of the return statement in the current Java Language Specification (§14.17) features an innocuous-looking sentence: It can be seen, then, that a return statement always completes abruptly. Other statements that “always complete abruptly” include break (§14.15), continue (§14.16), and of course throw (§14.18). So what? Well, Java also has try-finally blocks (§14.20). As … Continue reading “Jumping out of Java finally”

Amazing NetBeans JAR Vanishing Act

Today I encountered a bizarre and obscure misbehavior of NetBeans 7.3.1 that you should be aware of when writing JavaFX applications. The situation: I wanted to add some text files to a JavaFX project that should be copied to the output folder at every build. The NetBeans way to do this is to add a … Continue reading “Amazing NetBeans JAR Vanishing Act”