2

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.

Heisenbug
  • 38,762
  • 28
  • 132
  • 190

3 Answers3

5

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.

Sergii Zagriichuk
  • 5,389
  • 5
  • 28
  • 45
3

I'm not absolutely sure, but it might work to simply replace Hashtable with Dictionary, which apparently is what the method wants.

Dictionary labelTable = new Dictionary();
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.setLabelTabel(labelTable);
Ninto
  • 306
  • 2
  • 3
  • Also Eclipse could miss the generics, you can try Hashtable labelTable = new Hashtable(); or Dictionary labelTable = new Hashtable(); – Sorceror Jun 15 '11 at 20:05
  • 1
    Anyway I'm using Java 1.6.0_23 and Eclipse Helios SR1 and I don't get the error on the posted code.. – Sorceror Jun 15 '11 at 20:07
  • Dictionary is supperclass of HashTable and your variant the same as previous – Sergii Zagriichuk Jun 15 '11 at 20:14
  • +1 Sorry, I overlooked your suggested generic declaration before. One essential virtue is exposing type errors such as this. – trashgod Jun 15 '11 at 20:37
1

Oh..thank you both @Ninto and @Sorceror. You are right. It was an include error:

import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;

instead of :

import java.util.Hashtable;
Heisenbug
  • 38,762
  • 28
  • 132
  • 190