Label « JSlider « Java Swing Q&A





1. Change displayable labels for a JSlider?    stackoverflow.com

I have a JSlider with a min of 0 and a max of 10,000. I have the major tick marks set at 1,000. If I were to paint the labels now ...

2. A JSlider with both minor and major labels?    stackoverflow.com

Is it possible for both minor and major ticking labels to be displayed on the same JSlider?

3. Tooltip in labels in JSlider    stackoverflow.com

I want to create a JSlider with labels, which have a tooltip.

JSlider slider = new JSlider();
JLabel label = new JLabel("First");

slider.setPaintLabels(true);
Hashtable<Integer, JLabel> labels = new Hashtable<Integer, JLabel>();

label.setToolTipText("Tooltip");

labels.put(new Integer(0), label);
slider.setLabelTable(labels);
But, this code does ...

4. Need to label a tick stop on snap to JSlider    coderanch.com

import java.awt.*; import java.util.*; import javax.swing.*; public class SliderTest { public static void main(String[] args) { JLabel rare = new JLabel("rare"), medium = new JLabel("medium"), well = new JLabel("well"); Hashtable ht = new Hashtable(); ht.put(new Integer(0), rare); ht.put(new Integer(1), medium); ht.put(new Integer(2), well); JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 2, 1); slider.setMajorTickSpacing(1); slider.setPaintTicks(true); slider.setSnapToTicks(true); slider.setLabelTable(ht); slider.setPaintLabels(true); JFrame f = new JFrame(); ...

5. How to display labels on a JSlider    coderanch.com

6. Displaying Value Label in JSlider    coderanch.com

7. Assigning labels to JSliders?    java-forums.org

I wanted to add labels above the sliders, and with the size of the panel and layout manager, it always places them to the left of the slider (or to the right if added after). I guess this was preemptive, though; it works fine to the side, so no need for it above.