Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to access a non-String-Object from ResourceBundle inside fxml

seb.Mar 7 2017 — edited Mar 14 2017

Hi, I got a question. I have a Resource class that extends java.util.ListResourceBundle, which holds several values. These are not only Strings but also doubles, for example. Now I want to access these values inside my FXML. It works very easy with String resources with the % sign, but did not work for me with any other type.

Here is some example code:

Resource class:

public class Resources extends java.util.ListResourceBundle {

  
private static final Object[][] OBJECTS = new Object[][]{
  
{"FOO", "foo"},
  
{"BAR", 123d}
  
}

  
@Override
  
protected Object[][] getContents() {
  
return OBJECTS;
  
}

}

Loading the FXML in Application class:

Resources resources = new Resources();
FXMLLoader loader = new FXMLLoader(getClass().getResource("/foo.fxml"), resources);
Parent root = loader.load();

FXML:

<Label text="%FOO">
<Polygon>
  
<points>
  
<Double fx:value="0"/>
  
<Double fx:value="0"/>
  
<Double fx:value="%BAR"/>
  
<Double fx:value="0"/>
  
</points>
</Polygon>

The first line in FXML works perfectly fine, however the line with %BAR crashes with javafx.fxml.LoadException

I posted this question on SO two weeks ago but never got an answer. (java - JavaFX: Access in FXML to a non-String-Object from a ResourceBundle - Stack Overflow )

I hope you can help me.

Thanks a lot!

This post has been answered by bouye-JavaNet on Mar 13 2017
Jump to Answer

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Apr 11 2017
Added on Mar 7 2017
2 comments
335 views