Out of the box, we provide a model for a JSlider
.
This BoundedRangeModel
is constructed via the GlazedListsSwing
factory class. It is used to bind a JSlider
to an instance of
ThresholdList
.
However, since a JSlider
has only one value that can be set,
the ThresholdList
can be bound to the slider in two different
ways:
Lower Threshold Slider:
In this mode, the BoundedRangeModel
interacts with the
ThresholdList
so that all values in the list are between the
current value of the slider and the maximum value defined for the slider. A
BoundedRangeModel
of this type can be constructed using
the GlazedListsSwing.lowerRangeModel()
factory method.
Upper Threshold Slider:
In this mode, the BoundedRangeModel
interacts with the
ThresholdList
so that all values in the list are between the
minimum value of the slider and the current value defined for the slider. A
BoundedRangeModel
of this type can be constructed using
the GlazedLists.upperRangeModel()
factory method.
For our application, we want a range from 1
to the slider value so
we need to use a slider model in Upper Threshold Slider mode. We will set the slider's
initial value to 5
so that no issues are filtered out when the
application starts.
// create the threshold slider BoundedRangeModel priorityFilterRangeModel = GlazedListsSwing.lowerRangeModel(priorityFilteredIssues); priorityFilterRangeModel.setRangeProperties(1, 0, 1, 5, false); JSlider priorityFilterSlider = new JSlider(priorityFilterRangeModel); Hashtable priorityFilterSliderLabels = new Hashtable(); priorityFilterSliderLabels.put(new Integer(1), new JLabel("Low")); priorityFilterSliderLabels.put(new Integer(5), new JLabel("High")); priorityFilterSlider.setLabelTable(priorityFilterSliderLabels); priorityFilterSlider.setMajorTickSpacing(1); priorityFilterSlider.setSnapToTicks(true); priorityFilterSlider.setPaintLabels(true); priorityFilterSlider.setPaintTicks(true);