Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a Slider control with multiple nodes in JavaFX

I want to make a Slider(bar) control with multiple nodes.

The idea is be able to set intervals of time using them.

For example:

                      13:00 pm        4:00 pm
10:00 am ----------------[]------------[]-------------------- 11:00 pm
                   A             B                    C
  • A = 10:00 am - 13:00 pm
  • B = 13:00 am - 4:00 pm
  • C = 4:00 am - 11:00 pm

But i just notice that i can't add more nodes to the control. There's any way to do that? Or an alternative solution?

Edit:

In the example are just two nodes, but it can be multiple nodes.

like image 542
exsnake Avatar asked Oct 31 '22 02:10

exsnake


1 Answers

If you want to pick ranges, and you are using JavaFX8, then you could use RangeSlider from ControlsFX.

The RangeSlider control is simply a JavaFX Slider control with support for two 'thumbs', rather than one. A thumb is the non-technical name for the draggable area inside the Slider / RangeSlider that allows for a value to be set.

It is absolutely what you need, it works as a simple slider but you have a low value and a high value.

On how to configure the Slider to display time values, a litte hint can be this question:

How can I set the JavaFX Slider to format for time?

I don't really see the usecase where more than two thumbs are needed, and I doubt that a complete solution exists, therefore in this case I guess you have to implement your own control. The source of RangeSlider is open, so if you decide to go in this direction I would recommend to firstly check out that.

like image 152
DVarga Avatar answered Nov 04 '22 06:11

DVarga