JavaFX CSS Error ( Property Stylesheets does not exist )

后端 未结 4 1876
故里飘歌
故里飘歌 2021-01-04 23:23

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 dis

相关标签:
4条回答
  • 2021-01-04 23:38

    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).

    0 讨论(0)
  • 2021-01-04 23:40

    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.

    0 讨论(0)
  • 2021-01-04 23:51

    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>
      
    0 讨论(0)
  • 2021-01-04 23:59

    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.

    0 讨论(0)
提交回复
热议问题