Is it possible to set the default color of a ColorPicker in FXML, or do I have to set the color in the FXML controllers initialize method?
This can be done by using the <value>
tag along with the <Color>
tag, and an import for the Color type. This is briefly mentioned in the official tutorial, but without a full example.
Note SceneBuilder doesn't not appear to support editing of this. However SceneBuilder is non-destructive, in that you can open a file with a nested <value>
, make changes, and <value>
will be preserved.
Example
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.ColorPicker?>
<?import javafx.scene.paint.Color?>
<ColorPicker
xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<value>
<Color blue="0.0" green="0.0" red="1.0" />
</value>
</ColorPicker>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With