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

Multiple style classes of a Spinner are not loaded via FXMLLoader

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windwos 10
      java version "1.8.0_181"
      Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      If i use more than one style class in the FXML file for a spinner, just the first class is loaded.
      This is independent of using attribute (e.g. <Spinner styleClass="class1, class2") or nodes (e.g. <Spinner><styleClass><String fx:value="class1"/>...)
      Other controlls (e.g. TextField, Combobox) seems to work fine.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      assigned style classes to Spinner: ["font-larger", "font-bold"]
      ACTUAL -
      assigned style classes to Spinner: "font-larger"

      ---------- BEGIN SOURCE ----------
      example.css
      .font-larger {
          -fx-font-size: 20;
      }
      .font-bold {
          -fx-font-weight: bold;
      }


      example.fxml
      <VBox xmlns="http://javafx.com/javafx/8.0.181" xmlns:fx="http://javafx.com/fxml/1">
        <children>
          <TextField>
            <styleClass>
              <String fx:value="font-larger"/>
              <String fx:value="font-bold"/>
            </styleClass>
          </TextField>
          <Spinner fx:id="spinner" editable="true" min="0" max="100" initialValue="12">
            <styleClass>
              <String fx:value="font-larger"/>
              <String fx:value="font-bold"/>
            </styleClass>
          </Spinner>
        </children>
      </VBox>

      java class
      public class SpinnerStyleClass extends Application {

      public static void main(String[] args) {
      Application.launch(args);
      }

      @Override
      public void start(Stage primaryStage) throws Exception {
      FXMLLoader loader = new FXMLLoader(Thread.currentThread().getContextClassLoader().getResource("example.fxml"));
      Parent root = loader.load();

      Scene scene = new Scene(root);
      scene.getStylesheets().add(Thread.currentThread().getContextClassLoader().getResource("example.css").toExternalForm());

      // expected result ["font-larger", "font-bold"]
      assert root.lookup("#spinner").getStyleClass().size() == 2;

      primaryStage.setScene(scene);
      primaryStage.show();
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Wrap String values in ObservableArrayList:

          <Spinner fx:id="spinner" editable="true" min="0" max="100" initialValue="12">
            <styleClass>
              <FXCollections fx:factory="observableArrayList">
                <String fx:value="font-larger"/>
                <String fx:value="font-bold"/>
              </FXCollections>
            </styleClass>
          </Spinner>


      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            aghaisas Ajit Ghaisas
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: