I couldn't get to the solution I actually wanted, I would've hoped to be able to include a file (fxml, css, values, etc) and reference directly. The best I could do is to create a POJO with a property for each constant, then defining an instance of the POJO in fxml.
The problem with this is each fxml will be creating a new instance of a class, which is a little wasteful seeing as the constants are static in nature.
The following is what I did:
FXMLConstants.java
// Class instance containing global variables to be referenced in fxml files. This is to allow us to use constants similarly to how Android's xml structure does
public class FXMLConstants
{
private static final DoubleProperty marginSmall = new SimpleDoubleProperty(10);
private static final DoubleProperty marginMedium = new SimpleDoubleProperty(15);
private static final DoubleProperty marginLarge = new SimpleDoubleProperty(25);
public Double getMarginSmall()
{
return marginSmall.getValue();
}
public Double getMarginMedium()
{
return marginMedium.getValue();
}
public Double getMarginLarge()
{
return marginLarge.getValue();
}
}
Example.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.net.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import com.example.FXMLConstants?>
<GridPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<fx:define>
<FXMLConstants fx:id="fxmlConsts" />
</fx:define>
<padding>
<Insets bottom="$fxmlConsts.marginMedium" left="$fxmlConsts.marginLarge" right="$fxmlConsts.marginLarge" top="$fxmlConsts.marginMedium" />
</padding>
<children>
<Label text="Test" GridPane.columnIndex="0" GridPane.rowIndex="0" />
</children>
</GridPane>