Here you can find the source of setMinMaxSliderLabels(JSlider slider, String[] labels)
Parameter | Description |
---|---|
slider | a parameter |
labels | a parameter |
public static void setMinMaxSliderLabels(JSlider slider, String[] labels)
//package com.java2s; //License from project: Open Source License import java.util.Hashtable; import javax.swing.JLabel; import javax.swing.JSlider; public class Main { /**//w w w. j ava 2 s .c om * Set the label for the minimum and the maximum value of a slider. The slider * will not show values for intermediate labels. * @param slider * @param labels */ public static void setMinMaxSliderLabels(JSlider slider, String[] labels) { setSliderLabels(slider, new int[] { slider.getMinimum(), slider.getMaximum() }, labels); } /** * Set the labels of a slider. * @param slider * @param values * @param labels */ public static void setSliderLabels(JSlider slider, int[] values, String[] labels) { 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); } slider.setLabelTable(labelTable); } }