Search code examples
javaswingjslider

problem with setLabelTable method to customize JSlider's lables


According to this tutorial, one should do the following to customize JSlider's lables:

JSlider framesPerSecond = new JSlider(JSlider.VERTICAL,
                                      FPS_MIN, FPS_MAX, FPS_INIT);
framesPerSecond.addChangeListener(this);
framesPerSecond.setMajorTickSpacing(10);
framesPerSecond.setPaintTicks(true);

//Create the label table
Hashtable labelTable = new Hashtable();
labelTable.put( new Integer( 0 ), new JLabel("Stop") );
labelTable.put( new Integer( FPS_MAX/10 ), new JLabel("Slow") );
labelTable.put( new Integer( FPS_MAX ), new JLabel("Fast") );
framesPerSecond.setLabelTable( labelTable ); //ERROR

framesPerSecond.setPaintLabels(true);

Actually Eclipse complain that setLabelTable want's a Dictionary not a HashTable ( I'm using sun sdk 1.6.0_25). The error is the following:

The method setLabelTable(Dictionary) in the type JSlider is not applicable for the arguments (Hashtable)

All the examples I found over Internet tells me to do like that.

So, what's the problem?

EDIT:

my question was wrong. It was just an include error. Have a look at my answer.


Solution

  • As I just commented Dictionary is supperclass of HashTable and you can put HashTable setLabelTabel, but if eclipse shows you this error we can think about two cases :

    • you are not using java.util.Hashtable

    • you are not using javax.swing.JSlider

    I think the first is your problem just chek it.