The <number> JavaFX CSS Data Type is the CSS equivalent of the Java double primitive, and is defined as one or more digits, optionally separated by a single decimal point, and (also optionally) preceded by a single “+” or “-” operator denoting its sign.

The <number> data type is related to the <integer> data type, which resembles the Java int primitive

Although the <number> data type is bounded by the range of double values available in Java (1.7E +/- 308 to 15 digits), in some cases, the number is only meaningful within defined bounds.

Some examples of this are

  • Setting the Slider’s -fx-major-tick-unit to a value less than zero will produce the warning:
Failed to set css [-fx-major-tick-unit] on <details specific to program> due to 'MajorTickUnit cannot be less than or equal to 0.'

Syntax

/*  Valid syntax  */
152      Integers are converted by the parser to numbers
15.2     Positive floating point numbers
-15.2    Negative floating point numbers
+15.2    Positive floating point numbers with leading + 
0.0      Zero
.124     Floating point number with no leading <integer>

/*  Invalid syntax  */
-3.4e-2  Scientific notation of any kind
fifty    Any letters

Specifically to be aware of here, as of JavaFX 15, the CSS interpreter can’t handle scientific notation, which you otherwise might expect.

Values

The JavaFX CSS interpreter isn’t a fully-compliant CSS Interpreter, nor does it support all CSS-values you might expect for the related CSS property.

<number> can have the following values:

ValueDescription
[+|-]? [<integer>]? [ “.” ]? [<integer>]Optional leading signOptional leading integerOptional decimal pointThe only mandatory element is the final integer

Example

The number data type is used in multiple JavaFX CSS properties including the slider's tick unit

CSS:

.slider{
    -fx-major-tick-unit: 33.333333333333;
    -fx-show-tick-marks: true;
    -fx-show-tick-labels: true;
}

.label{
    -fx-background-color: #fcc200;
    -fx-font-weight: bold;
}

FXML:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<VBox alignment="CENTER" prefHeight="250.0" prefWidth="300" spacing="25.0" stylesheets="@../css/styles.css"
      xmlns="http://javafx.com/javafx/10.0.2-internal">
    <Label alignment="CENTER" maxWidth="300" text="<number> example" />
   <Slider />
   <TextArea prefHeight="200.0" prefWidth="200.0" text="This slider has 3 major ticks, separated by 33.3333, which was defined using the <number> CSS data type" wrapText="true" />
    <padding>
        <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
    </padding>
</VBox>

See Also