I have a GluonFX Maven Java17 Linux application that works fine when I run gluonfx:run and gluonfx:runagent. However, when I build it using gluonfx:build and then run the standalone app I am missing CSS settings, menu item labels, etc.
The menu items are interesting because they are there but don't have any name labels. It's the same with right-click context menus in that they appear but with no labels.
Maybe the menu item labels are also being affected by failing to load CSS content.
What is the runtime difference between gluonfx:run and running the app that would make this happen?
Has anyone else seen this?
Firstly, the standard Maven structure of src/main/java, src/main/test is not adhered to but instead src/apppackages, test/apppackages. Then inside Maven we have the following to point to the correct locations:
<build>
...
<sourceDirectory>${project.basedir}/src</sourceDirectory
<testSourceDirectory>${project.basedir}/test</testSourceDirectory>
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
...
The CSS files are typically loaded within the .fxml files; eg:
...
<stylesheets>
<URL value="@classfilename.css" />
</stylesheets>
Inside class the CSS files are typiclly loaded as follows:
URL urlCSS = getClass().getResource("classcssfile.css");
and fxml files loaded as follows:
URL url = getClass().getResource("About.fxml");
Like to add that built a second version of the software using the standard Java src/resources structure and got the same issue in not correctly rendering controls.
GluonFX/GraalVM version: graalvm-svm-java17-linux-gluon-22.1.0.1-Final
*** Steps To Reproduce ***
Go to [https://start.gluon.io/] and generate the minimal app by unchecking everything so that the code looks like that below.
run mvn gluonfx:run, followed by mvn gluonfx:runagent. In both cases you will see the Label in blue.
Now run mvn gluonfx:build. Double-clicking the resulting app you will not see the blue Label.
The "com/mycompany/sample/styles.css" entry is there in META-INF/resource-config.json
When run in Terminal, we get a warning related to the un-named module:
./My\ Gluon\ Application Jul 23, 2023 2:01:40 PM com.sun.javafx.application.PlatformImpl startup WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @71c7db30'
package com.mycompany.sample;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage stage) {
String javaVersion = System.getProperty("java.version");
String javafxVersion = System.getProperty("javafx.version");
Label label = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
ImageView imageView = new ImageView(new Image(Main.class.getResourceAsStream("openduke.png")));
imageView.setFitHeight(200);
imageView.setPreserveRatio(true);
VBox root = new VBox(30, imageView, label);
root.setAlignment(Pos.CENTER);
Scene scene = new Scene(root, 640, 480);
scene.getStylesheets().add(Main.class.getResource("styles.css").toExternalForm());
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}