Module MaterialFX

Class MFXSliderSkin

java.lang.Object
javafx.scene.control.SkinBase<MFXSlider>
io.github.palexdev.materialfx.skins.MFXSliderSkin
All Implemented Interfaces:
Skin<MFXSlider>

public class MFXSliderSkin extends SkinBase<MFXSlider>
This is the Skin used by default by every MFXSliderl.

To be honest, I always thought that making a slider would be a much easier task, but this skin but this skin proves just the opposite. Don't get me wrong, if you calmly read the code it is intuitive but still, one of the most complicated skins I've ever made so far.

At the core a slider is simply a progress bar that the user can adjust with an icon (the thumb). So, conceptually it is easy, but computing the value based on the mouse drag or press, computing the layout based on the value, managing the popup position and visibility, positioning the ticks correctly, the possibility to change the thumb and the popup, the bidirectional feature, all of that is quite tricky, but, I must say that I'm happy with the final result.

A little note on how the popup visibility is managed.

The popup is shown when an arrow key is pressed or the mouse is pressed on the thumb.

To hide the popup a PauseTransition of 800 milliseconds is played and at the end the popup is hidden.

This transition, the release timer, should ensure that the popup is not closed when the value is adjusted rapidly.
  • Constructor Details

    • MFXSliderSkin

      public MFXSliderSkin(MFXSlider slider)
  • Method Details

    • setBehavior

      protected void setBehavior()
      Calls sliderHandlers(), sliderListeners(), skinBehavior().
    • showPopup

      protected void showPopup()
      If the popup is not null, stops the release timer and shows the popup with a fade in animation.
    • hidePopup

      protected void hidePopup()
      If the popup is not null, hides the popup with a fade out animation.
    • buildRectangle

      protected Rectangle buildRectangle(String styleClass)
      Responsible for building the track and the bars for the slider.
    • buildTick

      protected Node buildTick()
      Responsible for creating the slider's major ticks.
    • computeMinHeight

      protected double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset)
      Overrides:
      computeMinHeight in class SkinBase<MFXSlider>
    • computePrefWidth

      protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset)
      Overrides:
      computePrefWidth in class SkinBase<MFXSlider>
    • computePrefHeight

      protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset)
      Overrides:
      computePrefHeight in class SkinBase<MFXSlider>
    • computeMaxWidth

      protected double computeMaxWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset)
      Overrides:
      computeMaxWidth in class SkinBase<MFXSlider>
    • computeMaxHeight

      protected double computeMaxHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset)
      Overrides:
      computeMaxHeight in class SkinBase<MFXSlider>
    • dispose

      public void dispose()
      Specified by:
      dispose in interface Skin<MFXSlider>
      Overrides:
      dispose in class SkinBase<MFXSlider>
    • layoutChildren

      protected void layoutChildren(double x, double y, double w, double h)
      Overrides:
      layoutChildren in class SkinBase<MFXSlider>