Jekyll2022-10-09T06:55:19+00:00http://abhinay.xyz/feed.xmlAbhinay AgarwalA site for Java/FXFlags for JavaFX application2022-10-03T07:00:00+00:002022-10-03T07:00:00+00:00http://abhinay.xyz/javafx/2022/10/03/OpenJFX%20flags<p>JavaFX has various flags to either add debug logs or switch configuration.
However, there is no central location which lists all these flags.
There have been multiple attempts to officially do this but most of them failed:</p>
<ul>
<li><a href="https://bugs.openjdk.java.net/browse/JDK-8091497">Need an official document covering Prism flags</a></li>
</ul>
<p>This is my humble attempt to categorise and list all the flags:</p>
<h3 id="general">General</h3>
<table>
<thead>
<tr>
<th>Flag</th>
<th>Default</th>
<th>Options</th>
<th>Details</th>
</tr>
</thead>
<tbody>
<tr>
<td>glass.platform</td>
<td>platform specific</td>
<td>macosx, windows, linux, gtk, ios, Monocle, swt</td>
<td>Sets the platform for JavaFX application</td>
</tr>
<tr>
<td>jdk.gtk.verbose</td>
<td>false</td>
<td>Boolean</td>
<td>Verbose logging related to GTK on Linux</td>
</tr>
<tr>
<td>jdk.gtk.version</td>
<td>3 (since JFX 11)</td>
<td>2, 3</td>
<td>Toggle between GTK versions. Default is 3 since OpenJFX 11</td>
</tr>
<tr>
<td>javafx.verbose</td>
<td>false</td>
<td>boolean</td>
<td>Verbose logging for JavaFX</td>
</tr>
<tr>
<td>monocle.platform</td>
<td>MX6,OMAP,Dispman,Android,X11,Linux,Headless</td>
<td>MX6,OMAP,Dispman,Android,X11,Linux,Headless</td>
<td>Series of cascading fallbacks for what NativePlatform types</td>
</tr>
</tbody>
</table>
<h3 id="accessibility">Accessibility</h3>
<table>
<thead>
<tr>
<th>Flag</th>
<th>Default</th>
<th>Options</th>
<th>Details</th>
</tr>
</thead>
<tbody>
<tr>
<td>glass.accessible.force</td>
<td>false</td>
<td>boolean</td>
<td>Force enable a11y on older platforms</td>
</tr>
</tbody>
</table>
<h3 id="animation">Animation</h3>
<table>
<thead>
<tr>
<th>Flag</th>
<th>Default</th>
<th>Options</th>
<th>Details</th>
</tr>
</thead>
<tbody>
<tr>
<td>javafx.animation.pulse</td>
<td>60</td>
<td>number in hz</td>
<td>override the default pulse rate</td>
</tr>
<tr>
<td>javafx.animation.framerate</td>
<td>60</td>
<td>number in hz</td>
<td>override the default frame rate</td>
</tr>
<tr>
<td>javafx.animation.fullspeed</td>
<td>false</td>
<td>boolean</td>
<td> </td>
</tr>
<tr>
<td>com.sun.scenario.animation.adaptivepulse</td>
<td>false</td>
<td>boolean</td>
<td> </td>
</tr>
<tr>
<td>com.sun.scenario.animation.fixed.pulse.length</td>
<td>false</td>
<td>boolean</td>
<td>increment each animation by a fixed length of time for each pulse instead of using system time</td>
</tr>
<tr>
<td>com.sun.scenario.animation.AnimationMBean.enabled</td>
<td>false</td>
<td>boolean</td>
<td> </td>
</tr>
</tbody>
</table>
<h3 id="quantum">Quantum</h3>
<table>
<thead>
<tr>
<th>Flag</th>
<th>Default</th>
<th>Options</th>
<th>Details</th>
</tr>
</thead>
<tbody>
<tr>
<td>quantum.debug</td>
<td>false</td>
<td>boolean</td>
<td>Force enable a11y on older platforms</td>
</tr>
<tr>
<td>quantum.multithreaded</td>
<td>true</td>
<td>boolean</td>
<td>Disables multi-threaded toolkit</td>
</tr>
<tr>
<td>quantum.norenderjobs</td>
<td>false</td>
<td>boolean</td>
<td>Quantum will stop submitting render jobs</td>
</tr>
<tr>
<td>quantum.singlethreaded</td>
<td>false</td>
<td>boolean</td>
<td>Enable single GUI Threading. Can cause a drop in FPS</td>
</tr>
<tr>
<td>quantum.verbose</td>
<td>false</td>
<td>boolean</td>
<td>Verbose logging in Quantum toolkit</td>
</tr>
</tbody>
</table>
<h3 id="prism">Prism</h3>
<table>
<thead>
<tr>
<th>Flag</th>
<th>Default</th>
<th>Options</th>
<th>Details</th>
</tr>
</thead>
<tbody>
<tr>
<td>prism.allowhidpi</td>
<td>true</td>
<td>boolean</td>
<td>Disables hi-dpi scaling</td>
</tr>
<tr>
<td>prism.cacheshapes</td>
<td>complex</td>
<td>complex, all</td>
<td>Shape caching optimizations</td>
</tr>
<tr>
<td>prism.debug</td>
<td>false</td>
<td>boolean</td>
<td>Debug output in prism</td>
</tr>
<tr>
<td>prism.debugfonts</td>
<td>false</td>
<td>boolean</td>
<td>Debug output related to fonts</td>
</tr>
<tr>
<td>prism.dirtyopts</td>
<td>true</td>
<td>boolean</td>
<td>Disables dirty region optimizations</td>
</tr>
<tr>
<td>prism.dirtyregioncount</td>
<td>6</td>
<td>number between 0 and 15</td>
<td>Sets the number of dirty regions to use</td>
</tr>
<tr>
<td>prism.disableBadDriverWarning</td>
<td>false</td>
<td>boolean</td>
<td>Disable bad driver check warning</td>
</tr>
<tr>
<td>prism.forceGPU</td>
<td>false</td>
<td>boolean</td>
<td>Force prism to run in HW accelerated mode</td>
</tr>
<tr>
<td>prism.forcepaint</td>
<td>false</td>
<td>boolean</td>
<td>Force scene repaint on every frame</td>
</tr>
<tr>
<td>prism.newiio</td>
<td>true</td>
<td>boolean</td>
<td>Disable use of new javafx-iio image loader</td>
</tr>
<tr>
<td>prism.noFallback</td>
<td>false</td>
<td>boolean</td>
<td>disable fallback to another toolkit if prism couldn’t be initialized</td>
</tr>
<tr>
<td>prism.order</td>
<td>platform specific</td>
<td>j2d, d3d, es2, sw</td>
<td>Graphics engines</td>
</tr>
<tr>
<td>prism.primtextures</td>
<td>0</td>
<td>true, false, <number></number></td>
<td>Sets texture mask size</td>
</tr>
<tr>
<td>prism.printallocs</td>
<td>false</td>
<td>boolean</td>
<td>Print texture allocation data</td>
</tr>
<tr>
<td>prism.printrendergraph</td>
<td>false</td>
<td>boolean</td>
<td>Prints out the render graph, annotated with dirty opts information</td>
</tr>
<tr>
<td>prism.printStats</td>
<td>0</td>
<td>true or number (<=0 means do not print)</td>
<td>Prism statistics print frequency</td>
</tr>
<tr>
<td>prism.rasterizerorder</td>
<td>marlin</td>
<td>nativepisces, javapisces, marlin, doublemarlin</td>
<td>Select an alternative to default rasterizer</td>
</tr>
<tr>
<td>prism.scrollcacheopt</td>
<td>false</td>
<td>boolean</td>
<td>Scrolling cache optimization</td>
</tr>
<tr>
<td>prism.showdirty</td>
<td>false</td>
<td>boolean</td>
<td>Draws overlay rectangles showing where the dirty regions were</td>
</tr>
<tr>
<td>prism.showoverdraw</td>
<td>false</td>
<td>boolean</td>
<td>Draws overlay rectangles showing not only the dirty regions, but the count each area within that dirty region was drawn (covered by bounds of a drawn object)</td>
</tr>
<tr>
<td>prism.trace</td>
<td>false</td>
<td>boolean</td>
<td>Trace output in prism</td>
</tr>
<tr>
<td>prism.verbose</td>
<td>false</td>
<td>boolean</td>
<td>Verbose output in prism</td>
</tr>
</tbody>
</table>
<h3 id="scaling">Scaling</h3>
<table>
<thead>
<tr>
<th>Flag</th>
<th>Default</th>
<th>Options</th>
<th>Details</th>
</tr>
</thead>
<tbody>
<tr>
<td>glass.gtk.uiScale</td>
<td> </td>
<td>decimal e.g. “1.25”</td>
<td>Force UI scaling factor</td>
</tr>
<tr>
<td>glass.win.forceIntegerRenderScale</td>
<td>true</td>
<td>boolean</td>
<td>Disables force integer rendering scale</td>
</tr>
<tr>
<td>glass.win.minHiDPI</td>
<td> </td>
<td>percentage e.g. “125%”</td>
<td> </td>
</tr>
<tr>
<td>glass.win.renderScale</td>
<td> </td>
<td>percentage e.g. “125%”</td>
<td> </td>
</tr>
<tr>
<td>glass.win.uiScale</td>
<td> </td>
<td>percentage e.g. “125%”</td>
<td> </td>
</tr>
<tr>
<td>sun.java2d.uiScale</td>
<td> </td>
<td>percentage e.g. “125%”</td>
<td> </td>
</tr>
<tr>
<td>sun.java2d.uiScale.enabled</td>
<td> </td>
<td>true</td>
<td> </td>
</tr>
<tr>
<td>swt.autoScale</td>
<td> </td>
<td>number e.g. “125”</td>
<td> </td>
</tr>
</tbody>
</table>JavaFX has various flags to either add debug logs or switch configuration. However, there is no central location which lists all these flags. There have been multiple attempts to officially do this but most of them failed: Need an official document covering Prism flagsScroll Events in VirtualFlow based Controls2022-05-23T06:07:35+00:002022-05-23T06:07:35+00:00http://abhinay.xyz/javafx/2022/05/23/Scroll%20Event%20in%20ListView<p>JavaFX has the following methods on Node to register scroll events either
via touch or mouse scroll wheel:</p>
<ul>
<li><a href="https://openjfx.io/javadoc/17/javafx.graphics/javafx/scene/Node.html#onScrollProperty">onScrollProperty</a></li>
<li><a href="https://openjfx.io/javadoc/17/javafx.graphics/javafx/scene/Node.html#onScrollStartedProperty">onScrollStartedProperty</a></li>
<li><a href="https://openjfx.io/javadoc/17/javafx.graphics/javafx/scene/Node.html#onScrollFinishedProperty">onScrollFinishedProperty</a></li>
</ul>
<p>These methods work on all Nodes except VirtualFlow based controls i.e.
ScrollPane, ListView, TableView, TreeView, TreeTableView, etc.</p>
<h1 id="explanation">Explanation</h1>
<p>VirtualFlow used in these controls is responsible for scrolling the content.
The VirtualFlow has an event handler for scroll events which consumes the event
and doesn’t allow it to bubble up to the control.
Therefore, event handler attached to the control for scroll events aren’t invoked.</p>
<p>Q. Can’t we just get rid of the event consumption in VirtualFlow
and let these controls behave like any other Node?</p>
<p>Unfortunately, no. Imagine a ListView placed inside a ScrollPane.
If VirtualFlow does not consume the event,
a scroll action will scroll both the ListView and the ScrollPane.</p>
<h1 id="solution">Solution</h1>
<p>In case a scroll event is required on one of these controls, an event filter can be used instead.
<em>N.B.</em> Do not consume these events on event capturing phase.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>var listView = new ListView();
listView.addEventFilter(ScrollEvent.ANY, event -> {
// code
});
</code></pre></div></div>
<h1 id="reference">Reference</h1>
<p>Comments on the following issues have some insights on why this design approach was taken:</p>
<ul>
<li><a href="https://bugs.openjdk.java.net/browse/JDK-8096155">JDK-8096155</a></li>
<li><a href="https://bugs.openjdk.java.net/browse/JDK-8096847">JDK-8096847</a></li>
</ul>JavaFX has the following methods on Node to register scroll events either via touch or mouse scroll wheel:FXML friendly custom controls2018-05-09T03:19:35+00:002018-05-09T03:19:35+00:00http://abhinay.xyz/javafx/2018/05/09/FXML%20friendly%20custom%20controls<p>JavaFX has support for extending containers and controls. Most of us writing these
extensions want them to be FXML friendly. JavaFX provides a number of annotations
to help improve FXML support and you should definitely have
them on your controls.</p>
<p>The annotations are as follows:</p>
<ul>
<li>@DefaultProperty</li>
<li>@NamedArg</li>
<li>@IDProperty</li>
</ul>
<p>Lets have a look at each of these annotations and their usage in details:</p>
<h1 id="defaultproperty">@DefaultProperty</h1>
<p>Specifies a property to which child element(s) will be added or
set when an explicit child property tag is not defined in FXML.</p>
<p>For example:</p>
<p><code class="language-plaintext highlighter-rouge">Pane</code> has a default property defined as “children”, which corresponds to the children property.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>@DefaultProperty("children")
public class Pane extends Region {
...
}
</code></pre></div></div>
<p><code class="language-plaintext highlighter-rouge">ImageView</code> has default property defined as “image”, which corresponds to the image property.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>@DefaultProperty("image")
public class ImageView extends Node {
...
}
</code></pre></div></div>
<p>Consider the following FXML:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code><Pane fx:id=”pane”>
<children>
<ImageView>
<image>
<Image url="">
</image>
</ImageView>
</children>
</Pane>
</code></pre></div></div>
<p>Since <code class="language-plaintext highlighter-rouge">@DefaultProperty</code> is defined for both <code class="language-plaintext highlighter-rouge">Pane</code> and <code class="language-plaintext highlighter-rouge">ImageView</code>, we can re-write the FXML as:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code><Pane fx:id=”pane”>
<ImageView>
<Image url="">
</ImageView>
</Pane>
</code></pre></div></div>
<p>There are a few things to keep in mind while annotating a class with <code class="language-plaintext highlighter-rouge">@DefaultProperty</code>:</p>
<ul>
<li>Class should define a public default constructor</li>
<li>Class should not have any constructor with parameters annotated with <code class="language-plaintext highlighter-rouge">@NamedArg</code></li>
</ul>
<h1 id="namedarg">@NamedArg</h1>
<p>Used to define arguments for a class which will be used by the <code class="language-plaintext highlighter-rouge">FXMLLoader</code>
to instantiate the class when its used inside a FXML.</p>
<p>For example, one of the constructor in <code class="language-plaintext highlighter-rouge">Image</code> is declared as:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>public Image(@NamedArg("url") String url) {
...
}
</code></pre></div></div>
<p>This indicates that an Image can be declared in FXML with a url property.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code><ImageView>
<Image url="/icon.png"/>
</ImageView>
</code></pre></div></div>
<p>Just like <code class="language-plaintext highlighter-rouge">@DefaultProperty</code>, here are a few things you should keep in mind while
annotating parameters with <code class="language-plaintext highlighter-rouge">@NamedArg</code>:</p>
<ul>
<li><code class="language-plaintext highlighter-rouge">@NamedArg</code> should be used to define properties which can be injected as parameters
to the constructor.</li>
<li>If the properties annotated with <code class="language-plaintext highlighter-rouge">@NamedArg</code> are not provided in the FXML, the FXMLLoader will:
<ul>
<li>Call the default constructor, if present.</li>
<li>Call the parameterized constructor with <code class="language-plaintext highlighter-rouge">null</code> values.</li>
</ul>
</li>
<li><code class="language-plaintext highlighter-rouge">@DefaultProperty</code> and <code class="language-plaintext highlighter-rouge">@NamedArg</code> should not be used on the same class. In case they are used,
<code class="language-plaintext highlighter-rouge">@DefaultProperty</code> will not work.</li>
</ul>
<h1 id="idproperty">@IDProperty</h1>
<p>Specifies a property which can be used by the <code class="language-plaintext highlighter-rouge">FXMLLoader</code> to set the value from <code class="language-plaintext highlighter-rouge">fx:id</code>. For all child classes of <code class="language-plaintext highlighter-rouge">Node</code>, it is mapped to the <code class="language-plaintext highlighter-rouge">id</code> property of <code class="language-plaintext highlighter-rouge">Node</code>.</p>
<p>In case a class extends from <code class="language-plaintext highlighter-rouge">Node</code> or any of its subclasses, you do not need to worry about this
property. Classes which do not extend from Node and desire FXML support, needs to declare
<code class="language-plaintext highlighter-rouge">@IDProperty</code>.</p>
<p>The following classes in JavaFX, which do not extend <code class="language-plaintext highlighter-rouge">Node</code>, use them:</p>
<ul>
<li>ContextMent</li>
<li>MenuItem</li>
<li>Tab</li>
<li>TableColumnBase</li>
<li>ToolTip</li>
</ul>
<p>At the time of writing this post, <code class="language-plaintext highlighter-rouge">@IDProperty</code> is still a private API and is present
in <code class="language-plaintext highlighter-rouge">com.sun.javafx.beans</code> package. Therefore, all controls using this property will fail
to compile under JDK 9 and later. There is an
<a href="https://bugs.openjdk.java.net/browse/JDK-8090835">open issue</a>
to move it to the public <code class="language-plaintext highlighter-rouge">javafx.beans</code> package.</p>
<p>As I stated in the beginning of the post, these annotations <strong>should</strong> be used
on every custom control. If you are extending a Node which has these annotations
on them, you can choose to either skip or override them.</p>
<p>Lets make all controls FXML friendly!!!</p>JavaFX has support for extending containers and controls. Most of us writing these extensions want them to be FXML friendly. JavaFX provides a number of annotations to help improve FXML support and you should definitely have them on your controls.Welcome to my blog!2017-12-21T17:04:00+00:002017-12-21T17:04:00+00:00http://abhinay.xyz/personal/2017/12/21/Welcome-to-my-blog<p>Hi,</p>
<p>Welcome to my blog!</p>
<p>The blog will mostly contain posts about Java and JavaFX,
but I will try to keep it interesting by adding various other stuff.</p>
<p>Thanks.</p>Hi,