Java JSlider setSliderLabels(JSlider slider, int[] values, String[] labels)

Here you can find the source of setSliderLabels(JSlider slider, int[] values, String[] labels)

Description

Set the labels of a slider.

License

Open Source License

Parameter

Parameter Description
slider a parameter
values a parameter
labels a parameter

Declaration

public static void setSliderLabels(JSlider slider, int[] values,
        String[] labels) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Hashtable;
import javax.swing.JLabel;
import javax.swing.JSlider;

public class Main {
    /**/*from  w  w w.j  av a2  s. c  o  m*/
     * 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);
    }
}

Related

  1. createSliderPanel(final JSlider slider, String label, int width)
  2. fixWinSliderUI(JSlider s)
  3. makeLabelSliderPanelHorizontal(String text, JSlider slider)
  4. reapplyFontSize(JSlider slider)
  5. setMinMaxSliderLabels(JSlider slider, String[] labels)
  6. setSliderPercent(JSlider s, double percent)
  7. setSliderValue(JSlider slider, float f)