Dmitrij  Krupa
Dmitrij Krupa

Reputation: 121

stylesheets in FXML (JDK 9)

doesn't work after update to JDK 9.

<stylesheets>
  <URL value="@MainView.css" />
</stylesheets>

Caused by: java.lang.IllegalArgumentException: Unable to coerce @MainView.css to class java.net.URL.

Can you help me?

Upvotes: 1

Views: 541

Answers (2)

Lozitsky
Lozitsky

Reputation: 183

As mentioned above, there are two ways to connect css. For this to work, create a "resources" folder in the root directory such as "src" and put the file there. Then you can try it:

<stylesheets>
    <URL value="@/resources/MainView.css" />
</stylesheets>

or

stylesheets="@/resources/MainView.css"

Upvotes: 0

pdem
pdem

Reputation: 4067

It works for me as an attribute on root level, here is my Index.fxml as an example:

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.*?>
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" styleClass="app"   stylesheets="@Index.css" 
    fx:controller="fr.pdem.view.IndexController" fx:id="root">
    <!-- all the nodes-->

</AnchorPane>

My strategy is to use one css file per FXML, so I don't need a list a files.

Side note: Not sure it is a good practice to use wildcards on imports, but just for the example, it works.

Upvotes: 0

Related Questions