I am making a JavaFX application where the content is loaded from JXML. I am now at the point where I am trying to change the language of the components dynamically without reloading the entire scene. I have seen this answer which created an observable ResourceFactory, which is exactly what I'm looking for, however it relies on having the keys for the controls available to look up the internationalised text from the resource bundle.
How can I get the raw key from say a Button or a Label that is loaded from an FXML file using FXMLLoader.load(...? When I look at the attributes of the controls I can see the text attribute which gives me the text visible on screen, but what I'm after is the key used to look this text up - e.g. the '%homepage.enterbuttonlabel' rather than 'Enter'
I've traced thorough the FXMLLoader.load method and found this in FXMLLoader$element:235
public void processInstancePropertyAttributes() throws IOException {
if (instancePropertyAttributes.size() > 0) {
for (Attribute attribute : instancePropertyAttributes) {
processPropertyAttribute(attribute);
}
}
}
At this point the instancePropertyAttributes contain the element 'text' which has the '%homepage.enterbuttonlabel' that I'm after, but it would appear processing this value replaces it with the internationalised text.
FXMLLoader$element is a private inner class of FXMLLoader, so I can't see how to override anything that could store this value in a new attribute before processing erases it. Short of Copying / Reimplementing the FXMLLoader class is there any way I can get access to that value?