Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8128765

Problems with FXML and CSS styling


    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: fx2.0
    • Fix Version/s: None
    • Component/s: javafx
    • Labels:
    • Environment:

      Windows 7, JDK7, JavaFX 2.0 b40

    • Subcomponent:


      In this report I am referring to the latest version of the FXML documentation
      form August, 15th together with build 40 of JavaFX and JDK7.


      In contrast to the documentation, defining an ID via fx:id does NOT
      automatically set the ID-field of a node too and thus styling does
      not work. You have to define the node ID separately in order to get
      styling working but this is cumbersome because you have to
      specify it twice. It is also error-prone because 'fx:id' and 'id'
      look so similar but have a different meaning.

      <Label id="messageLabel" fx:id="messageLabel" text="messages go here" />

      #messageLabel {
          -fx-text-fill: red;


      In contrast to the documentation the @FXML annotation is also needed for all public fields and methods.
      The below controller fragment only works with all the @FXMLs in there. Otherwise I get a
      java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

      @FXML public TextField firstNameField;
      @FXML public TextField lastNameField;
      @FXML public Label messageLabel;

      @FXML public void handleButtonAction(ActionEvent event) {


      How do you set for example the minWidth of a label via FXML and a predefined constant like USE_PREF_SIZE?
      I did not have any success.


        1. fxml_test.css
          0.0 kB
        2. fxml_test.fxml
          0.3 kB
        3. FXMLSample1.zip
          3 kB
        4. FXMLTest.java
          0.7 kB
        5. FXMLTestController.java
          0.4 kB



            • Assignee:
              gkbrown Greg Brown (Inactive)
              dpausjfx Dr. Michael Paus (Inactive)
            • Votes:
              0 Vote for this issue
              1 Start watching this issue


              • Created: