List of utility methods to do JSlider
void | setMinMaxSliderLabels(JSlider slider, String[] labels) Set the label for the minimum and the maximum value of a slider. setSliderLabels(slider, new int[] { slider.getMinimum(), slider.getMaximum() }, labels); |
void | setSliderLabels(JSlider slider, int[] values, String[] labels) Set the labels of a slider. assert (slider != null && values != null && labels != null); assert (values.length == labels.length); Hashtable labelTable = new Hashtable(); for (int i = 0; i < values.length; i++) { assert (values[i] >= slider.getMinimum()); assert (values[i] <= slider.getMaximum()); JLabel label = new JLabel(labels[i]); labelTable.put(new Integer(values[i]), label); ... |
void | setSliderPercent(JSlider s, double percent) Set the slider value as a percentage between its min and max BoundedRangeModel r = s.getModel();
s.setValue(r.getMinimum() + (int) (percent * (r.getMaximum() - r.getMinimum())));
|
void | setSliderValue(JSlider slider, float f) Set a slider value based on a fraction [0,1] value. if (f < 0 || f > 1) throw new IllegalArgumentException("f (" + f + ") must be between [0, 1]"); int v = (int) (slider.getMinimum() + f * (slider.getMaximum() - slider.getMinimum())); slider.setValue(v); |