Aleksander H.
Aleksander H.

Reputation: 53

How to set default color for ColorPicker in FXML

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?

Upvotes: 5

Views: 3746

Answers (1)

Adam
Adam

Reputation: 36743

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

Upvotes: 4

Related Questions