I am using the latest jme javafx library and 3.1 alpha 3. I tried defining the .css in the .fxml file, tried applying it manually on my FXMLHud through addStyleSheet() and even tried to add it mabually on my root node of the FXMLHud. It does not get applied at run-time. No errors so I know my resource path is correct. When I apply it on the ,fxml file it comes up nicely in the preview view of SceneBuilder.
Has anyone run into this problem?
I used an other approach to apply CSS:
static void initGui(GuiManager guiManager) {
//see http://blog.idrsolutions.com/2014/04/use-external-css-files-javafx/
Scene scene = guiManager.getjmeFXContainer().getScene();
FxPlatformExecutor.runOnFxApplication(() -> {
Font.loadFont(MainApp.class.getResource("/Fonts/Eduardo-Barrasa.ttf").toExternalForm(), 10);
Font.loadFont(MainApp.class.getResource("/Fonts/bobotoh.ttf").toExternalForm(), 10);
String css = MainApp.class.getResource("/Interface/main.css").toExternalForm();
scene.getStylesheets().clear();
scene.getStylesheets().add(css);
});
}
david_bernard_31:
I used an other approach to apply CSS:
static void initGui(GuiManager guiManager) {
//see http://blog.idrsolutions.com/2014/04/use-external-css-files-javafx/
Scene scene = guiManager.getjmeFXContainer().getScene();
FxPlatformExecutor.runOnFxApplication(() -> {
Font.loadFont(MainApp.class.getResource("/Fonts/Eduardo-Barrasa.ttf").toExternalForm(), 10);
Font.loadFont(MainApp.class.getResource("/Fonts/bobotoh.ttf").toExternalForm(), 10);
String css = MainApp.class.getResource("/Interface/main.css").toExternalForm();
scene.getStylesheets().clear();
scene.getStylesheets().add(css);
});
}
Never thought of adding the style-sheet to the scene instead of the hud nodes. Works perfectly! Thank you!
If you only want it for one hud:
this.editorHud = new FXMLHud<EditorHudController>("de/visiongamestudios/client/editor/editorScreen.fxml") {
@Override
protected ResourceBundle addCustomRessources(final ResourceBundle ressources) {
return I18NProvider.getBundle();
}
};
this.editorHud.addStyleSheet("de/visiongamestudios/editor/editor.css");
this.editorHud.precache();
You need to do this before precaching or adding it to the GuiManager. Btw. that way seen above you can register your message bundles
1 Like