JSlider: setLabelTable(Dictionary labels) : JSlider « javax.swing « Java by API






JSlider: setLabelTable(Dictionary labels)

 
import java.awt.BorderLayout;
import java.util.Hashtable;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSlider;

public class MainClass {
  public static void main(String args[]) throws Exception {
    String title = (args.length == 0 ? "Sample Slider" : args[0]);
    JFrame frame = new JFrame(title);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JSlider js4 = new JSlider(JSlider.VERTICAL);
    Hashtable<Integer, JLabel> table = new Hashtable<Integer, JLabel>();
    table.put(0, new JLabel("O"));
    table.put(10, new JLabel("Ten"));
    table.put(25, new JLabel("Twenty-Five"));
    table.put(34, new JLabel("Thirty-Four"));
    table.put(52, new JLabel("Fifty-Two"));
    table.put(70, new JLabel("Seventy"));
    table.put(82, new JLabel("Eighty-Two"));
    table.put(100, new JLabel("100"));
    js4.setLabelTable(table);
    js4.setPaintLabels(true);
    js4.setSnapToTicks(true);
    frame.add(js4, BorderLayout.EAST);
    frame.setSize(300, 200);
    frame.setVisible(true);

  }

}


           
         
  








Related examples in the same category

1.JSlider.isFilled
2.Slider.horizontalThumbIcon
3.new JSlider(int min, int max)
4.new JSlider(int min, int max, int value)
5.new JSlider(int orientation)
6.new JSlider(int orientation, int min, int max, int value)
7.JSlider: addChangeListener(ChangeListener l)
8.JSlider: getExtent()
9.JSlider: getMaximum()
10.JSlider: getMinimum()
11.JSlider: getPaintTicks()
12.JSlider: getSnapToTicks()
13.JSlider: getValue()
14.JSlider: getValueIsAdjusting()
15.JSlider: setExtent(int extent)
16.JSlider: setInverted(boolean b)
17.JSlider: setMajorTickSpacing(int v)
18.JSlider: setMaximum(int maximum)
19.JSlider: setMinimum(int minimum)
20.JSlider: setMinorTickSpacing(int v)
21.JSlider: setOrientation(int orientation)
22.JSlider: setPaintLabels(boolean t)
23.JSlider: setPaintTicks(boolean t)
24.JSlider: setPaintTrack(boolean b)
25.JSlider: setPreferredSize(Dimension preferredSize)
26.JSlider: setSnapToTicks(boolean b)
27.JSlider: setToolTipText(String s)
28.JSlider: setValue(int n)
29.extends JSlider