Java JSlider setMinMaxSliderLabels(JSlider slider, String[] labels)

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

Description

Set the label for the minimum and the maximum value of a slider.

License

Open Source License

Parameter

Parameter Description
slider a parameter
labels a parameter

Declaration

public static void setMinMaxSliderLabels(JSlider slider, 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 {
    /**//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);
    }
}

Related

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