I would like to make a spinner to enter the time just like this : Youtube Vidéo
If someone knows where the source code is hiding, it would be perfect. But if not, I would like to try and implement it myself, but how do I even make 3 different (focusable ?) textarea like this ?
Edit : Here is what I got, but I would like to able to select the hours and the increment the hours not only the minutes (and same for the seconds ofc)
Spinner<LocalTime> spinner = new Spinner(new SpinnerValueFactory() {
{
setConverter(new LocalTimeStringConverter(FormatStyle.MEDIUM));
}
@Override
public void decrement(int steps) {
if (getValue() == null)
setValue(LocalTime.now());
else {
LocalTime time = (LocalTime) getValue();
setValue(time.minusMinutes(steps));
}
}
@Override
public void increment(int steps) {
if (this.getValue() == null)
setValue(LocalTime.now());
else {
LocalTime time = (LocalTime) getValue();
setValue(time.plusMinutes(steps));
}
}
});
spinner.setEditable(true);
This is the result I get :
Thanks
change your converter constructor to:
I think the best approach for selecting the individual parts of the editor is to check the
caretPosition
in the editor and increment/decrement the appropriate portion as required. You can also set aTextFormatter
on the editor to control the allowed input, etc.Here's a quick attempt: not intended to be production quality but should be a good start:
And here's a quick example of using it: