I want to implement a date chooser using a JSlider. The user should be able to use the slider to freely choose between two previously known dates. I've seen examples like this one:
But I want to do the same, using only one slider. The minimal distance between two points (tick) should be one day. Any hints how to implement that?
If you want to have a slider with min = 1.1.2012 and max = 10.1.2012 just create a slider with min = 0 and max = number of days in between, then add the selected number to 1.1.2012.
I assume 10.1.2012 means January 10th, thus your slider would have min = 0 and max = 9. Then set the labels accordingly.
I can't to image how to do that with one JSlider
, because there you'd have bunch of days, there are some workarounds for Double/RangeSlider
, but I think better and easiest would be implements JSpinner with SpinnerDateModel
, or best options is look for Custom Java Calendar
or DatePicker
EDIT (@Robin)
First to answer your question: you can just use a JSlider
, use the number of days between your start and end date to determine the range, and use custom labels (by using for example the setLabelTable
method)
Now for user-friendliness, avoid this since
- Nobody is familiar with this concept. Every site/application nowadays uses a textfield, most of the time in combination with a calendar widget. That is what users expect, not a slider
- It will be hard to get all dates as labels on the slider due to the limited width. This means that a user have to interpolate / count to select his correct date
- If you stick to the slider approach, at least consider to add a textfield as well. Even a non-editable text field which shows the currently selected date would be a huge improvement over a slider (see point 2)