Note that there are some explanatory texts on larger screens.

plurals
  1. PODeclaring Variable In JavaFX CSS File
    primarykey
    data
    text
    <p>I've been inspecting the "caspian.css" distributed by Oracle in the JavaFX runtime library, and I see they have declared some color values as variables. Eg:</p> <pre><code>-fx-base: #d0d0d0; // Caspian.css, Line 47 </code></pre> <p>...and then they used it as value of some other property, like:</p> <pre><code>-fx-color: -fx-base; // Caspian.css, Line 96 </code></pre> <p><strong>Now</strong>, what I want to do is to declare a measurement unit (<code>-fx-radius-default: 10px</code>) and then use it everytime I need to set radius of a control, for instance:</p> <pre><code>-fx-border-radius: -fx-radius-default; -fx-background-radius: -fx-radius-default; </code></pre> <p>I have been unsuccessful so far. My question is: Is this possible, at all?</p> <hr> <p><em>Edit: Adding experiment details</em></p> <h1>Details</h1> <p>Here is my Experiment.fxml file that I created on JavaFX Scene Builder 1.1:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;?import java.lang.*?&gt; &lt;?import java.net.*?&gt; &lt;?import java.util.*?&gt; &lt;?import javafx.scene.control.*?&gt; &lt;?import javafx.scene.layout.*?&gt; &lt;?import javafx.scene.paint.*?&gt; &lt;AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml"&gt; &lt;children&gt; &lt;TextArea layoutX="200.0" layoutY="119.0" prefWidth="200.0" styleClass="track" wrapText="true" /&gt; &lt;/children&gt; &lt;stylesheets&gt; &lt;URL value="@css/Experiment.css" /&gt; &lt;/stylesheets&gt; &lt;/AnchorPane&gt; </code></pre> <p>And below is the <code>css/Experiment.css</code> that I have used:</p> <pre><code>* { -fx-radius-default: 10px; } .track { -fx-border-radius: -fx-radius-default; -fx-border-color: black; } </code></pre> <p>Unfortunately this doesn't work, giving an error message like this:</p> <blockquote> <p>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</p> </blockquote> <p>If I use plain syntax (<code>-fx-border-radius: 10px</code>), there is no problem with that.</p> <p>What am I doing wrong here?</p> <hr> <p><em>Edit: Conclusion</em></p> <h1>Conclusion: Not Possible</h1> <p>It seems what I am looking for is not possible with the current version of JavaFX, since "<a href="http://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html#typecolor">JavaFX CSS Reference Guide</a>" only mentions "looked-up colors", and not a generic concept of "variables". It would be a good feature, though... Just saying...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload