简体   繁体   中英

JavaFX CSS Error ( Property Stylesheets does not exist )

I have just began building a JavaFX application in IntelliJ using the latest Java7 SDK.

I have built my interface using Oracle Scene Builder, everything runs and displays fine on the preview, but when I try and compile my program I get the following error

`Property "stylesheets" does not exist or is read-only`

Judging against JavaFX Documentation the line stylesheets="@MainView.css" in my FXML does not appear invalid.

Does anybody know why I am getting this error? ( If I remove the link to the stylesheet my program compiles just fine, so the problem lies solely with the stylesheet, I'm stumped! )

You were creating an FXML in Scene Builder 2 and running in JDK 7. SB 2 "tries to" create Java 8 compatible FXML code. To fix the FXML:

  1. Remove the stylesheets="@MainView.css" attribute
  2. Add <?import java.net.*?> in the imports
  3. Add the below code at the end of parent pane, after </children> (in my case it was before </AnchorPane> ):

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

It turns out I needed to manually link the stylesheet in my start() method as JavaFX7 does not support the stylesheets tag.

To fix this I called the following command in my Start() method

root.getStylesheets().add(this.getClass().getResource("view/MainView.css").toExt‌​ernalForm());

Where root is the name of my FXMLLoader.

I've got the same error when I was trying to set my own CSS properties in my program. If you are not doing this, you are probably using some class that uses the CSS library introduced in JavaFX 8.

Try to update your JDK to the latest released version here .

If this still does not work, then somewhere in your application a CSS file is not being read correctly. There is probably some class with JavaFX bean properties that were wrongly mapped.

I get this error when opening the Scene Builder.

Installed jdk1.8, set it as my system's default (in /usr/lib/jvm/default-java) and modified my $PATH, none of which seemed to help.

Then updated the Scene Builder from 1.1 to 2.0, linked the 1.1 binary to the 2.0 version ( see this question ) and finally set the new Scene Builder path in Netbeans -> tools -> options -> Java -> JavaFX, which resolved the issue. Updating the default jdk version may or may not have had something to do with it.

The project itself used jdk1.8 already and I had no trouble running it; I only had issues opening them in the Scene Builder (got that error mentioned in the question title).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM