Suppose I have a custom JavaFX control Foo with a specialized case implemented as a nested static class Foo$Bar:
package com.acme;
import javafx.scene.control.Control;
public class Foo extends Control {
public static class Bar extends Foo {
}
}
Now I may want to use this control in an FXML, so I expect I should do something like this:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import com.acme.Foo$Bar?>
<VBox xmlns="http://javafx.com/javafx/8.0.191" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Foo.Bar/>
</children>
</VBox>
However, this results in the FXML being unloadable, raising the error
javafx.fxml.LoadException: Foo.Bar is not a valid type.
Curiously, if I change the import to read:
<?import com.acme.Foo.Bar?>
the FXML loads correctly, but my IDE (IntelliJ) marks the import as erroneous - I tend to agree with it, as it seems the FXML specification calls for importing using the fully-qualified class name, which in this case would be com.acme.Foo$Bar and not com.acme.Foo.Bar.
So is this a bug in JavaFX/FXMLLoader not recognizing fully-qualified names of static nested classes? Or is it a bug in IntelliJ, not recognizing a (poorly-documented?) legal import?