Issue
so I'm trying to run this project and it displays this error eventhough I added the fontawesomefx-8.2.jar
Caused by: java.lang.RuntimeException: Exception in Application start
method at
com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$159(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: javafx.fxml.LoadException: file:/C:/Users/Yasmine%20Daly/Downloads/Gaming%20Dashboard/Gaming%20Dashboard/dist/run1549224879/Gaming%20Dashboard.jar!/gaming/dashboard/UI.fxml:23
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097) at gaming.dashboard.GamingDashboard.start(GamingDashboard.java:13) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$166(LauncherImpl.java:863) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$179(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$177(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$178(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$152(WinApplication.java:177) ... 1 more Caused by: com.sun.javafx.fxml.PropertyNotFoundException: Property "iconName" does not exist or is read-only. at javafx.fxml.FXMLLoader$Element.processValue(FXMLLoader.java:348) at javafx.fxml.FXMLLoader$Element.processPropertyAttribute(FXMLLoader.java:325) at javafx.fxml.FXMLLoader$Element.processInstancePropertyAttributes(FXMLLoader.java:235) at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:767) at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532) ... 17 more Exception running application gaming.dashboard.GamingDashboard Java Result: 1
This is the UI file where the iconName exists and is underlined in red;
<FontAwesomeIcon iconName="MUSIC" layoutX="32.0" layoutY="134.0" size="1.5em" styleClass="sidebar-icon" />
<FontAwesomeIcon iconName="GEAR" layoutX="32.0" layoutY="175.0" size="1.5em" styleClass="sidebar-icon" />
<FontAwesomeIcon iconName="FILE" layoutX="34.0" layoutY="210.0" size="1.2em" styleClass="sidebar-icon" />
<FontAwesomeIcon iconName="DASHBOARD" layoutX="33.0" layoutY="242.0" size="1.2em" styleClass="sidebar-icon" />
<FontAwesomeIcon iconName="MUSIC" layoutX="32.0" layoutY="278.0" size="1.2em" styleClass="sidebar-icon" />
<FontAwesomeIcon iconName="HEART" layoutX="32.0" layoutY="368.0" size="1.2em" styleClass="sidebar-icon" />
<FontAwesomeIcon iconName="GEAR" layoutX="31.0" layoutY="399.0" size="1.5em" styleClass="sidebar-icon" />
Solution
If the following is addressed, then I can use font awesome icons from FXML:
- As it says, iconName is not a property of FontAwesomeIcon.
- FontAwesomeIcon is an enum and not a node, so I don't know how you would use it from FXML.
- There is a FontAwesomeIconView which is a node and has a property called glyphName and can be used instead.
- Ensure recent versions, Java/JavaFX 17.0.2 and fontawesomefx 4.7.0-9.1.2.
Following the instructions here:
Using the following fxml file:
<?xml version="1.0" encoding="UTF-8"?>
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.HBox?>
<HBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" spacing="10.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1">
<children>
<FontAwesomeIconView glyphName="MUSIC" size="1.5em" />
<FontAwesomeIconView glyphName="GEAR" size="1.5em" />
<FontAwesomeIconView glyphName="FILE" size="1.5em" />
<FontAwesomeIconView glyphName="DASHBOARD" size="1.5em" />
<FontAwesomeIconView glyphName="HEART" size="1.5em" />
</children>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</HBox>
Displays the following output in SceneBuilder:
To have this work in an app, you need to use a recent JDK and JavaFX, e.g. 17.0.2, as well as a recent FontAwesomeFX version and load the FXML into your app.
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx-fontawesome</artifactId>
<version>4.7.0-9.1.2</version>
</dependency>
See this question for an example of access via an app:
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class FontApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(FontApplication.class.getResource("fonts.fxml"));
stage.setScene(new Scene(fxmlLoader.load()));
stage.show();
}
public static void main(String[] args) {
launch();
}
}
Answered By - jewelsea
Answer Checked By - Gilberto Lyons (JavaFixing Admin)