Anatomy of a JavaFX slider

I want to add a few custom widgets to an application. For example: I’d like a dual slider that has a piano keyboard as part of the display, for setting a note range. To that end, I’ve forked and am studying the source code of the JFoenix “material” widgets. Since I want to build custom sliders, I thought I’d try look at the code being used for their JFXSlider widget.

This thread is to ask (and answer) questions as they come up. There is a LOT of background knowledge needed to understand what is going on here!

First question: there is a class for the widget (JFXSlider) and another for the skin for the widget (JFXSliderSkin). In the latter, object members are associated with .css values. I’m noticing that there are three different ways this is done:

// 1)
StackPane track = (StackPane) getSkinnable().lookup(".track");

// 2)
StackPane coloredTrack = new StackPane();
coloredTrack.getStyleClass().add("colored-track");

// 3)
Text sliderValue = new Text();
sliderValue.getStyleClass().setAll("slider-value");

In each case, the items in quotes are present in the file jfx-slider.css.

Any thoughts on why any one of these methods might be preferred over the other?

I’m continuing tomorrow with looking into the API specifics of each method (lookup/add/setAll). Maybe I’ll be able to find an answer. But just coming across this code for the first time, the answer isn’t obvious to me.

2 Likes

After tracing down multiple extends trails and looking up many APIs, it kind of became clear to me I needed more background than I realized. To remedy that, I found two library books that I’ve started reading.

  • The Definitive Guide to Modern Java Client with JavaFX, Chin/Vos/Weaver, Apress 2019
  • Mastering JavaFX8 Controls, Ebbers, 2014

Both read pretty well so far. Am reading them in parallel. The first of the two is geared to IntelliJ and getting that running and getting used to it has been a task. But the nice thing is that it has included using the SceneBuilder tool.

Both books include making custom controls. I’m going to get this task done. Creating the controls I’ve envisioned is the biggest hurdle in the way of “finishing” the Leviaphon project.

1 Like