The <integer> JavaFX CSS Data Type is the CSS equivalent of the Java int primitive, and is defined as one or more digits, optionally preceded by a single “+” or “-” operator denoting its sign.

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

Behaviour

Although the <integer> data type is bounded by the range of integers available in Java (+2,147,483,647 to -2,147,483,648), in some cases, the integer is only meaningful within defined bounds.

Some examples of this are

  • Using <integer> to define the RGB values in the rbg() function of the <color> data type. An <integer> value of 255 corresponds to 100% of the specified color.
    • A negative number is interpreted as zero.
    • A number higher than 255 is interpreted as 255.
  • When used to define the number of tick counts in -fx-minor-tick-count
    • Selecting a high number may result in tick marks not being rendered, if JavaFX determines that tick marks can’t be sensibly displayed.
    • Selecting a very high number will result in the error Warning we tried to create more than 10000 minor tick marks on a NumberAxis.

Syntax

/*  Valid Syntax  */
100         A positive integer
-2475       A negative integer
+235        A positive integer with some personal insecurities.

/*  Invalid syntax  */
2.0        Decimal points, even if they correspond to an integer
15.         Decimal points, even without a decimal digit 
+---10      Only one optional +/- sign is allowed
five        No letters are allowed, even if they correspond to an integer.
_9          Only digits (0-9) are allowed. No special characters.
\35         Escaped Unicode characters, even if they are an integer
\4E94       Non-arabic numerals, even when escaped
3e4         Scientific notation.

Example

The integer data type is used in multiple JavaFX CSS properties including the slider's tick minor count

CSS:

.slider{
    -fx-minor-tick-count: 5;
    -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" xmlns:fx="http://javafx.com/fxml/1">
    <Label alignment="CENTER" maxWidth="300" text="<integer> example" />
   <Slider />
   <TextArea prefHeight="200.0" prefWidth="200.0" text="This slider has 5 minor ticks, which was defined using the <integer> CSS data type" wrapText="true" />
    <padding>
        <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
    </padding>
</VBox>

See Also