简体   繁体   English

setLabelTable方法的问题,以自定义JSlider的标签

[英]problem with setLabelTable method to customize JSlider's lables

According to this tutorial , one should do the following to customize JSlider's lables: 根据本教程 ,应该执行以下操作来自定义JSlider的标签:

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). 实际上Eclipse抱怨setLabelTable想要的是Dictionary而不是HashTable(我正在使用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) JSlider类型中的方法setLabelTable(Dictionary)不适用于参数(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. 看看我的答案。

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 : 正如我刚刚评论的那样,Dictionary是HashTable的超级类,你可以把HashTable设置为setLabelTabel,但是如果eclipse显示这个错误,我们可以考虑两种情况:

  • you are not using java.util.Hashtable 你没有使用java.util.Hashtable

  • you are not using javax.swing.JSlider 你没有使用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替换Hashtable ,这显然是方法所需要的。

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. 哦..感谢@Ninto和@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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM