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 -D<i>name=value</i>
” 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 available. This prevents frequent display driver crashes and application freezes on my Windows 10 system with an integrated Intel GPU. My WPF applications have the same problem, so I guess the fault lies with Intel’s graphics drivers.-Dglass.win.minHiDPI=1
enables universal DPI coordinate scaling at all Windows DPI resolutions, including 125% (120 DPI) which is normally special-cased to scale only JavaFX default sizes but not explicitly specified coordinates. Some blurriness which might occur is less harmful, in my opinion, than breaking the entire window layout.
These options work very well. There’s just one problem: to specify them as command-line flags, you need to run all your JavaFX applications from the command line or dedicated batch files (shell scripts). Directly executing applications from a file explorer does not transmit any command-line flags, and that has led to many annoying situations: “Why is that program suddenly freezing? Oh, I forgot to enable software rendering…”
JAVA_TOOL_OPTIONS
Looking around for a way to set such flags globally for all Java programs, I discovered the immensely useful environment variable JAVA_TOOL_OPTIONS. You can set this variable to any combination of options that a java/javaw
command line would take, and its contents are then prepended to any subsequent execution of a Java program. Just what we need!
The JDK comes with a few utilities that let you easily verify whether your application has picked up a system property specified via JAVA_TOOL_OPTIONS
(or in any other way). After setting the variable, run your JavaFX application and open a command prompt. Now do the following:
- Type
jps
orjcmd
to discover your application’s process identifier (PID). - Type “
jinfo <i>PID</i>
” or “jcmd <i>PID</i> VM.system_properties
” where PID is the discovered number. - A list of system properties and possibly other runtime settings will appear. Check that this list includes the properties you specified, e.g. “
prism.order = sw
.”
You can find the official documentation for these utilities at Oracle’s website but I also recommend Dustin Marx’s highly readable overview articles: jcmd (Java SE 7) is the new all-in-one tool, jinfo and jps (Java SE 5) are older specialized tools which are still around for now.
2 thoughts on “JavaFX and JAVA_TOOL_OPTIONS”