Discussions
Categories
- 197.1K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.7K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 555 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.3K SQL Developer
- 296.3K Development
- 17 Developer Projects
- 139 Programming Languages
- 293K Development Tools
- 110 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 158 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 466 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
CSS Image loading problem by dynamically loading from fxml file?

963802
Member Posts: 31
h1. Introduction
The application I am developing loads an FXML file from a Controller. The FXML uses CSS and images for buttons are set in the CSS.
CSS directory structure
<package>.fxml
Images
<package>.fxml.resources.<subdir>
Example CSS Code
The fxml file does not load and causes the following error:
Any ideas of what might be going wrong?
h1. Attempted
I have attempted the following: tried changing the url of the image as an absolute path.
The application I am developing loads an FXML file from a Controller. The FXML uses CSS and images for buttons are set in the CSS.
CSS directory structure
<package>.fxml
Images
<package>.fxml.resources.<subdir>
Example CSS Code
.buttonImage { -fx-background-image: url("resources/subdir/image.png"); }Example loading fxml from controller code
URL location = getClass().getResource("/package/fxml/UI.fxml"); FXMLLoader fxmlLoader = new FXMLLoader(location); fxmlLoader.setLocation(location); fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory()); Parent root = (Parent)fxmlLoader.load(location.openStream()); Controller = (Controller) fxmlLoader.getController(); newPane.getChildren().add(root);h1. Problem
The fxml file does not load and causes the following error:
javafx.fxml.LoadException: Page language not specified.Note, the fxml file loaded correctly before images were added.
Any ideas of what might be going wrong?
h1. Attempted
I have attempted the following: tried changing the url of the image as an absolute path.
Best Answer
-
The problem are your onAction handlers. If you point to a Java controller they need to start with #. e.g. #profileEventFired
Answers
-
Your problem is not CSS but that your FXML can not be loaded. Show us you FXML File.
-
No Problem: Note, this is the actual FXML, my previous examples were simplifications of package names and class names in order to directly illustrate the problem. Note, I am using SceneBuilder to develop the FXML file.
<?xml version="1.0" encoding="UTF-8"?> <?import java.lang.*?> <?import java.net.*?> <?import java.util.*?> <?import javafx.collections.*?> <?import javafx.scene.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.text.*?> <AnchorPane id="AnchorPane" prefHeight="396.0000999999975" prefWidth="350.0" styleClass="mainFxmlClass" xmlns:fx="http://javafx.com/fxml" fx:controller="com.monkygames.kbmaster.controller.ProfileUIController"> <children> <Label layoutX="14.0" layoutY="14.0" text="Profiles"> <font> <Font size="18.0" /> </font> </Label> <GridPane layoutX="15.0" layoutY="44.0" prefHeight="99.0" prefWidth="335.0"> <children> <Label text="Type: " GridPane.columnIndex="0" GridPane.rowIndex="0" /> <ComboBox fx:id="typeCB" prefWidth="249.0" GridPane.columnIndex="1" GridPane.rowIndex="0"> <items> <FXCollections fx:factory="observableArrayList"> <String fx:value="Item 1" /> <String fx:value="Item 2" /> <String fx:value="Item 3" /> </FXCollections> </items> </ComboBox> <Label text="Program: " GridPane.columnIndex="0" GridPane.rowIndex="1" /> <ComboBox fx:id="programCB" prefWidth="249.0" GridPane.columnIndex="1" GridPane.rowIndex="1"> <items> <FXCollections fx:factory="observableArrayList"> <String fx:value="Item 1" /> <String fx:value="Item 2" /> <String fx:value="Item 3" /> </FXCollections> </items> </ComboBox> <Label text="Profile: " GridPane.columnIndex="0" GridPane.rowIndex="2" /> <ComboBox prefWidth="249.0" GridPane.columnIndex="1" GridPane.rowIndex="2"> <items> <FXCollections fx:factory="observableArrayList"> <String fx:value="Item 1" /> <String fx:value="Item 2" /> <String fx:value="Item 3" /> </FXCollections> </items> </ComboBox> </children> <columnConstraints> <ColumnConstraints fillWidth="false" halignment="RIGHT" hgrow="NEVER" maxWidth="-Infinity" minWidth="10.0" prefWidth="80.0" /> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> </columnConstraints> <rowConstraints> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> </rowConstraints> </GridPane> <HBox layoutX="14.0" layoutY="150.0" prefHeight="159.0" prefWidth="335.0"> <children> <Label text="Description: " /> <TextArea prefHeight="172.0" prefWidth="247.0" wrapText="true" /> </children> </HBox> <HBox alignment="CENTER" layoutX="11.0" layoutY="334.0" prefHeight="48.0" prefWidth="329.0"> <children> <Button fx:id="newProfileB" contentDisplay="GRAPHIC_ONLY" minHeight="48.0" minWidth="48.0" mnemonicParsing="false" onAction="profileEventFired" prefHeight="48.0" prefWidth="48.0" styleClass="newProfile" text="New Profile" /> <Button id="newProfileB" fx:id="cloneProfileB" contentDisplay="GRAPHIC_ONLY" minHeight="48.0" minWidth="48.0" mnemonicParsing="false" onAction="profileEventFired" prefHeight="48.0" prefWidth="48.0" styleClass="cloneProfile" text="Clone Profile" /> <Button id="newProfileB" fx:id="importProfileB" contentDisplay="GRAPHIC_ONLY" minHeight="48.0" minWidth="48.0" mnemonicParsing="false" onAction="profileEventFired" prefHeight="48.0" prefWidth="48.0" styleClass="importProfile" text="Import Profile" /> <Button id="newProfileB" fx:id="exportProfileB" contentDisplay="GRAPHIC_ONLY" minHeight="48.0" minWidth="48.0" mnemonicParsing="false" onAction="profileEventFired" prefHeight="48.0" prefWidth="48.0" styleClass="exportProfile" text="Export Profile" /> <Button id="newProfileB" fx:id="printPDFB" contentDisplay="GRAPHIC_ONLY" minHeight="48.0" minWidth="48.0" mnemonicParsing="false" onAction="profileEventFired" prefHeight="48.0" prefWidth="48.0" styleClass="pdfProfile" text="Print to PDF" /> <Button id="newProfileB" fx:id="deleteProfileB" contentDisplay="GRAPHIC_ONLY" minHeight="48.0" minWidth="48.0" mnemonicParsing="false" onAction="profileEventFired" prefHeight="48.0" prefWidth="48.0" styleClass="deleteProfile" text="Delete Profile" /> </children> </HBox> </children> <stylesheets> <URL value="@master.css" /> <URL value="@profile.css" /> </stylesheets> </AnchorPane>
Edited by: 960799 on Jan 4, 2013 8:58 PM
Edited by: 960799 on Jan 4, 2013 8:59 PM -
-
The problem are your onAction handlers. If you point to a Java controller they need to start with #. e.g. #profileEventFired
-
That fixed the problem! Thank you very much!
This discussion has been closed.