Class WColorPicker


  • public class WColorPicker
    extends WFormWidget
    A widget that provides a browser-native color picker.

    To act upon color value changes, connect a slot to the WFormWidget.changed() signal. This signal is emitted when the user changes the selected color, and subsequently closes the color picker.

    To act upon any color change, connect a slot to the colorInput() signal. Note that this signal may fire very quickly depending on how the browser's color picker works.

    At all times, the currently selected color may be accessed with the value() method.

    The widget corresponds to the HTML <input type="color"> tag. Note that this element does not support CSS color names. When manipulating this widget with WColor values, ensure they have valid RGB values or the color picker will reset to #000000.

    WColorPicker is an inline widget.

    See Also:
    WColor
    • Constructor Detail

      • WColorPicker

        public WColorPicker​(WContainerWidget parentContainer)
        Creates a color picker with the default color of black (#000000).
      • WColorPicker

        public WColorPicker​(WColor color,
                            WContainerWidget parentContainer)
        Creates a color picker with the given color value. Ensure the color has valid RGB values, or the color will be reset to #000000.
      • WColorPicker

        public WColorPicker​(WColor color)
        Creates a color picker with the given color value. Ensure the color has valid RGB values, or the color will be reset to #000000.

        Calls this(color, (WContainerWidget)null)

    • Method Detail

      • setColor

        public void setColor​(WColor value)
        Sets the selected color.

        The default value is #000000 (black).

        Ensure the color has valid RGB values, or the color will be reset to #000000.

        See Also:
        getColor()
      • colorInput

        public EventSignal colorInput()
        Event signal emitted when the selected color is changed.

        This signal is emitted whenever the selected color has changed. Unlike the WFormWidget.changed() signal, this signal is fired on every change, not only when the color picker is closed.

        In particular, on browsers with a draggable color picker (i.e. most common browsers), this signal fires every time the position changes. Use with caution.

        See Also:
        WFormWidget.changed()
      • getValueText

        public java.lang.String getValueText()
        Returns the current value of the color picker as a string.

        This is implemented as

        
         return color().cssText();
        
         
        Specified by:
        getValueText in class WFormWidget
      • setValueText

        public void setValueText​(java.lang.String value)
        Sets the current value of the color picker as a string. The string must be in a format from which WColor can determine RGB values (i.e. not a CSS color name), or the value will be set to #000000.

        This is implemented as

        
         setColor(WColor(value));
        
         

        Specified by:
        setValueText in class WFormWidget