Module MaterialFX

Class MFXLegacyComboBox<T>

All Implemented Interfaces:
Validated, Styleable, EventTarget, Skinnable

public class MFXLegacyComboBox<T> extends ComboBox<T> implements Validated
This is a restyle of the JavaFX's combo box.

For a combo box which more closely follows the guidelines of material design see MFXComboBox.

Extends ComboBox, redefines the style class to "mfx-legacy-combo-box" for usage in CSS and includes a MFXValidator. Also, introduces a new PseudoClass ":invalid" to specify the control's look when the validation fails.

A few notes on features and usage:

If you check ComboBox documentation you will see a big warning about using nodes as content because the scenegraph only allows for Nodes to be in one place at a time. I found a workaround to this issue using Node.snapshot(SnapshotParameters, WritableImage). Basically I make a "screenshot" of the graphic and then I use an ImageView to show it.

So let's say you have a combo box of labels with icons as graphic, when you select an item, it won't disappear anymore from the list because what you are seeing it's not the real graphic but a screenshot of it.

I recommend to use only nodes which are instances of Labeled since the toString() method is overridden to return the control's text.

See Also:
  • Property Details

  • Field Details

    • INVALID_PSEUDO_CLASS

      protected static final PseudoClass INVALID_PSEUDO_CLASS
  • Constructor Details

    • MFXLegacyComboBox

      public MFXLegacyComboBox()
    • MFXLegacyComboBox

      public MFXLegacyComboBox(ObservableList<T> observableList)
  • Method Details

    • getValidator

      public MFXValidator getValidator()
      Specified by:
      getValidator in interface Validated
      Returns:
      the MFXValidator instance of this control
    • getInvalidLineColor

      public Paint getInvalidLineColor()
      Gets the value of the property invalidLineColor.
      Property description:
      Specifies the color of the focused line when the validator state is invalid.

      This workaround is needed because I discovered a rather surprising/shocking bug. If you set the line color in SceneBuilder (didn't test in Java code) and the validator state is invalid, the line won't change color as specified in the CSS file, damn you JavaFX :)
    • invalidLineColorProperty

      public ObjectProperty<Paint> invalidLineColorProperty()
      Specifies the color of the focused line when the validator state is invalid.

      This workaround is needed because I discovered a rather surprising/shocking bug. If you set the line color in SceneBuilder (didn't test in Java code) and the validator state is invalid, the line won't change color as specified in the CSS file, damn you JavaFX :)
      See Also:
    • setInvalidLineColor

      public void setInvalidLineColor(Paint invalidLineColor)
      Sets the value of the property invalidLineColor.
      Property description:
      Specifies the color of the focused line when the validator state is invalid.

      This workaround is needed because I discovered a rather surprising/shocking bug. If you set the line color in SceneBuilder (didn't test in Java code) and the validator state is invalid, the line won't change color as specified in the CSS file, damn you JavaFX :)
    • updateComboItem

      protected void updateComboItem(ListCell<T> cell, T item, boolean empty)
      Defines the behavior of the button cell.

      If it's empty or the item is null, shows the prompt text.

      If the item is instanceof Labeled makes a "screenshot" of the graphic if not null, and gets item's text. Otherwise calls toString() on the item.

    • getLineColor

      public Paint getLineColor()
      Gets the value of the property lineColor.
      Property description:
      Specifies the line's color when the control is focused.
    • lineColorProperty

      public StyleableObjectProperty<Paint> lineColorProperty()
      Specifies the line's color when the control is focused.
      See Also:
    • setLineColor

      public void setLineColor(Paint lineColor)
      Sets the value of the property lineColor.
      Property description:
      Specifies the line's color when the control is focused.
    • getUnfocusedLineColor

      public Paint getUnfocusedLineColor()
      Gets the value of the property unfocusedLineColor.
      Property description:
      Specifies the line's color when the control is not focused.
    • unfocusedLineColorProperty

      public StyleableObjectProperty<Paint> unfocusedLineColorProperty()
      Specifies the line's color when the control is not focused.
      See Also:
    • setUnfocusedLineColor

      public void setUnfocusedLineColor(Paint unfocusedLineColor)
      Sets the value of the property unfocusedLineColor.
      Property description:
      Specifies the line's color when the control is not focused.
    • getLineStrokeWidth

      public double getLineStrokeWidth()
      Gets the value of the property lineStrokeWidth.
      Property description:
      Specifies the lines' stroke width.
    • lineStrokeWidthProperty

      public StyleableDoubleProperty lineStrokeWidthProperty()
      Specifies the lines' stroke width.
      See Also:
    • setLineStrokeWidth

      public void setLineStrokeWidth(double lineStrokeWidth)
      Sets the value of the property lineStrokeWidth.
      Property description:
      Specifies the lines' stroke width.
    • getLineStrokeCap

      public StrokeLineCap getLineStrokeCap()
      Gets the value of the property lineStrokeCap.
      Property description:
      Specifies the lines' stroke cap.
    • lineStrokeCapProperty

      public StyleableObjectProperty<StrokeLineCap> lineStrokeCapProperty()
      Specifies the lines' stroke cap.
      See Also:
    • setLineStrokeCap

      public void setLineStrokeCap(StrokeLineCap lineStrokeCap)
      Sets the value of the property lineStrokeCap.
      Property description:
      Specifies the lines' stroke cap.
    • isAnimateLines

      public boolean isAnimateLines()
      Gets the value of the property animateLines.
      Property description:
      Specifies if the lines switch between focus/un-focus should be animated.
    • animateLinesProperty

      public StyleableBooleanProperty animateLinesProperty()
      Specifies if the lines switch between focus/un-focus should be animated.
      See Also:
    • setAnimateLines

      public void setAnimateLines(boolean animateLines)
      Sets the value of the property animateLines.
      Property description:
      Specifies if the lines switch between focus/un-focus should be animated.
    • isValidated

      public boolean isValidated()
    • isValidatedProperty

      public StyleableBooleanProperty isValidatedProperty()
      Specifies if validation is required for the control.
    • setValidated

      public void setValidated(boolean isValidated)
    • getControlCssMetaDataList

      public static List<CssMetaData<? extends Styleable,?>> getControlCssMetaDataList()
    • createDefaultSkin

      protected Skin<?> createDefaultSkin()
      Overrides:
      createDefaultSkin in class ComboBox<T>
    • getUserAgentStylesheet

      public String getUserAgentStylesheet()
      Overrides:
      getUserAgentStylesheet in class Region
    • getControlCssMetaData

      public List<CssMetaData<? extends Styleable,?>> getControlCssMetaData()
      Overrides:
      getControlCssMetaData in class Control