- edited description
Can't use icons as a graphic into FXML
Hello,
I've got this piece of FXML code :
<...>
<Button ...>
<graphic>
<MaterialIcon glyphName="ADB" size="1em" glyphStyle="" />
</graphic>
</Button>
</...>
But it doesn't work, it triggers an InstanciationException when parsed by FXMLLoader.
What am I doing wrong ? Is there a way to fix this ?
Thanks !
Comments (12)
-
reporter -
repo owner Could you share the stack trace of the Exception?
-
repo owner - marked as task
-
repo owner - changed status to open
-
reporter Here is it :
javafx.fxml.LoadException: /C:/Users/natinusala/Documents/launchmycraft/workspace/Executable/bin/theme/dialog.fxml:46 at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source) at javafx.fxml.FXMLLoader.access$700(Unknown Source) at javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(Unknown Source) at javafx.fxml.FXMLLoader$ValueElement.processStartElement(Unknown Source) at javafx.fxml.FXMLLoader.processStartElement(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.load(Unknown Source) at fr.launchmycraft.launcher.DialogFactory.createDialog(DialogFactory.java:59) at fr.launchmycraft.launcher.DialogFactory.createDialog(DialogFactory.java:108) at fr.launchmycraft.launcher.ExecutableMain.main(ExecutableMain.java:75) Caused by: java.lang.InstantiationException: de.jensd.fx.glyphs.materialicons.MaterialIcon at java.lang.Class.newInstance(Unknown Source) at sun.reflect.misc.ReflectUtil.newInstance(Unknown Source) ... 14 more Caused by: java.lang.NoSuchMethodException: de.jensd.fx.glyphs.materialicons.MaterialIcon.<init>() at java.lang.Class.getConstructor0(Unknown Source) ... 16 more
-
reporter My guess is that MaterialIcon is an enum, so there is no public constructor and the instantiation obviously fails.
-
repo owner Thanks! Sorry silly question, but 1. FontAwesomeFX 8.6 is included on the classpath? And 2. there are imports in the FXML, like? <?import de.jensd.fx.glyphs.materialicons.*?>
-
repo owner "Works on my machine!" ;-)
-
reporter - Yes it is
- I only imported de.jensd.glpyhs.materialicons.MaterialIcon
But I just figured it out, I have to put MaterialIconView and not MaterialIcon and it works fine. It was my fault, I should have checked it beforehand. Sorry for the inconvenience x)
-
reporter I think that you should write a tiny documentation here on the repo, on how to use the library for both Java and FXML. I only found articles on your blog that weren't up to date anymore, hence my mistake. When we look at the code it's clear enough but I think that a documentation would be more efficient.
Anyway, sorry again, good luck for the next updates :)
-
repo owner Yes, I guess you're right. Will work on the documentation! Glad it's clarified now ;-)!
-
repo owner - changed status to resolved
- Log in to comment