Mega Code Archive

 
Categories / Java Tutorial / Swing
 

The slider allows you to use an arbitrary label at any particular major tick mark

import java.util.Dictionary; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JSlider; public class Main {   public static void main(String[] argv) throws Exception {     JSlider slider = new JSlider();          Dictionary table = slider.getLabelTable();     ImageIcon icon = new ImageIcon("icon.gif");     JLabel label = new JLabel(icon);     // Set at desired positions     table.put(new Integer(slider.getMinimum()), label);     table.put(new Integer(slider.getMaximum()), label);     // Force the slider to use the new labels     slider.setLabelTable(table);   } }