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 pro开发者_如何学编程blem?
EDIT:
my question was wrong. It was just an include error. Have a look at my answer.
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.
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);
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;
精彩评论