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

Problems with FXML and CSS styling

    XMLWordPrintable

Details

    • Bug
    • Resolution: Cannot Reproduce
    • P4
    • None
    • fx2.0
    • javafx
    • Windows 7, JDK7, JavaFX 2.0 b40

    Description

      In this report I am referring to the latest version of the FXML documentation
      http://fxexperience.com/wp-content/uploads/2011/08/Introducing-FXML.pdf
      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.

      Attachments

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

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:
              Imported: