Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default color for ColorPicker in FXML

Tags:

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?

like image 693
Aleksander H. Avatar asked Feb 24 '17 09:02

Aleksander H.


1 Answers

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>

Example

like image 139
Adam Avatar answered Sep 24 '22 10:09

Adam