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?
Asked
Active
Viewed 3,467 times
1 Answers
4
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>

Adam
- 35,919
- 9
- 100
- 137
-
Just what I was looking for. Thanks. – Aleksander H. Feb 24 '17 at 09:55
-
Cannot create instance of javafx.scene.paint.Color with given set of properties: [red, green, blue] – Wolfgang Fahl Mar 13 '20 at 15:18