This discussion is archived
4 Replies Latest reply: Nov 27, 2012 9:36 AM by jsmith RSS

Declaring Variable In JavaFX CSS File

883781 Newbie
Currently Being Moderated
also asked on stackoverflow: http://stackoverflow.com/questions/13566210/declaring-variable-in-javafx-css-file/13566682

So... caspian.css (the stylesheet file that is distributed in the javafx runtime, setting the default styles for UI controls) has CSS variables, it assigns color values to some variable and then use that variable as value of other CSS properties. I want to use that feature with `{number}px` type of values. For example, I want to declare one radius variable with value of 10px, and use that variable everytime I need to define a radius, thus if I need to change all radius values at once I can do that by changing the value of the variable. Is this possible?

-----

Here is my experiment (which was unsuccessful)

This is my Experiment.fxml
<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.net.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>

<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml">
  <children>
    <TextArea layoutX="200.0" layoutY="119.0" prefWidth="200.0" styleClass="track" wrapText="true" />
  </children>
  <stylesheets>
    <URL value="@css/Experiment.css" />
  </stylesheets>
</AnchorPane>
... and this is my "css/Experiment.css" file:
* {
    -fx-radius-default: 10px;
}
.track {
    -fx-border-radius: -fx-radius-default;
    -fx-border-color: black;
}
This code does not work, giving an error message:
Could not resolve '-fx-radius-default' while resolving lookups for '-fx-border-radius' from rule '*.track' in stylesheet file: /home/abdullah/codebase/src/package/css/Experiment.css

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points