Domanda

Secondo questo Tutorial, si dovrebbe fare quanto segue per personalizzare i lables di 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);

In realtà Eclipse si lamenta del fatto che SetLabeltable Want è un dizionario non un hashtable (sto usando Sun SDK 1.6.0_25). L'errore è il seguente:

Il metodo setLabeltable (Dizionario) nel tipo JSlider non è applicabile per gli argomenti (hashtable)

Tutti gli esempi che ho trovato su Internet mi dicono di fare così.

Allora, qual'è il problema?

MODIFICARE:

La mia domanda era sbagliata. Era solo un errore di includere. Dai un'occhiata alla mia risposta.

È stato utile?

Soluzione

Mentre ho appena commentato il dizionario è Superclass di Hashtable e puoi mettere Hashtable SetLabeltabel, ma se Eclipse ti mostra questo errore, possiamo pensare a due casi:

  • non stai usando java.util.hashtable

  • non stai usando javax.swing.jslider

Penso che il primo sia il tuo problema, solo.

Altri suggerimenti

Non ne sono assolutamente sicuro, ma potrebbe funzionare semplicemente per sostituire Hashtable insieme a Dictionary, che apparentemente è ciò che il metodo vuole.

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..grazie entrambi @ninto e @sorceror. Hai ragione. Era un errore di includere:

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

invece di :

import java.util.Hashtable;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top