Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scene Builder cannot load FXML with Ikonli 12.0.0 #124

Closed
sheydrich opened this issue Nov 29, 2020 · 7 comments
Closed

Scene Builder cannot load FXML with Ikonli 12.0.0 #124

sheydrich opened this issue Nov 29, 2020 · 7 comments
Assignees
Labels
Milestone

Comments

@sheydrich
Copy link

Hey,

thanks for your work on Ikonli!

I just updated from v11.5.0 to v12.0.0. I cannot open any of my existing FXMLs that contain FontIcons with an iconLiteral anymore. That is, when the file contains only an "empty" FontIcon, everything works. When the iconLiteral is defined, i get

java.lang.UnsupportedOperationException: Cannot resolve 'fa-bug'
	at org.kordamp.ikonli.AbstractIkonResolver.resolve(AbstractIkonResolver.java:73)
	at org.kordamp.ikonli.javafx.FontIcon.setIconLiteral(FontIcon.java:232)

Of course, I updated the JARs for Ikonli inside SceneBuilder.

Any idea what might be the problem?

@reardenSteel1964
Copy link

Same here!

@aalmiray
Copy link
Collaborator

Thank you for your report. Are you saying that an FXML like the following no longer works?
sampler.fxml

@sheydrich
Copy link
Author

Yes, this is correct. The file you posted does produce the same UnsupportedOperationException for 'fa-circle-thin' when opening with SceneBuilder, where these are the imported Libraries in SceneBuilder:
grafik

@aalmiray
Copy link
Collaborator

Here's the sampler-javafx app running, consuming the sampler.fxml file as is

sampler-javafx-fa

And here is the ikonli-browser displaying the legacy FontAwesome icon pack

ikonli-browser-fa

I suspect there's some specific issue in SceneBuilder. The given exception occurs when no suitable IkonHandler has been found. This tells me SB failed to load org.kordamp.ikonli.fontawesome.FontAwesomeIkonHandler, which should be loaded using ServiceLoader regardless of classpath or modulepath, although arguably JavaFX 9+ should always run on the modulepath.

@aalmiray
Copy link
Collaborator

The other thing that could be related to this problem is how IkonHandler instances are resolved in 12.0.0. The code in question is https://github.com/kordamp/ikonli/blob/master/core/ikonli-javafx/src/main/java/org/kordamp/ikonli/javafx/IkonResolver.java#L46-L51

    private static ServiceLoader<IkonHandler> resolveServiceLoader() {
        if (null != IkonHandler.class.getModule().getLayer()) {
            return ServiceLoader.load(IkonHandler.class.getModule().getLayer(), IkonHandler.class);
        }
        return ServiceLoader.load(IkonHandler.class);
    }

@eugener would you happen to have an idea how SceneBuilder loads new JARs when a ModuleLayer is available?

@aalmiray
Copy link
Collaborator

aalmiray commented Dec 6, 2020

Well, I can replicate the problem with SceneBuilder 11.0.0

Steps:

  1. Add ikonli-core, ikonli-javafx, ikonli-fontawesome-pack to Scenebuilder via the "JAR/FXML Manager" option found in the library section (left side).
  2. Add a FontIcon element to the main container. Configure fa-bug as the value for `iconLiteral. Notice that Scenebuilder does not render the icon.
  3. Save the FXML file and quit SceneBuilder.
  4. Launch SceneBuilder and load the previously saved FXML file.
  5. The reported exception occurs.

Given the error message I can tell Ikonli did not find a suitable IkonHandler for icons with fa- as prefix. This could be related to loading handlers using the ModuleLayer variant.

@aalmiray
Copy link
Collaborator

aalmiray commented Dec 6, 2020

Well, it turns SecneBuilder is cheeky and loads custom jars into the unnamed module, making the ModuleLayer null as a result. This makes the loading code in IkonResolver fail as shown before.
The ServiceLoader.load(IkonHandler.class) will fail as well. the only way to make it work is by passing a specific classloader.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants