Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / December 2004

Tip: Looking for answers? Try searching our database.

Using Dictionary class to label JSlider

Thread view: 
Konrad Den Ende - 12 Dec 2004 14:19 GMT
I'm trying to set labels on a JSlider and of what i see
i have to make an instance of Dictionary class. Since
it's an abstract class i have to extend it but the API
clearly states that isn't recommended.

Should i extend Dictionary class anyway or is there a
better way to put my own labels on the ticks?

Signature

Kindly
Konrad
---------------------------------------------------
May all spammers die an agonizing death; have no burial places;
their souls be chased by demons in Gehenna from one room to
another for all eternity and more.

Sleep - thing used by ineffective people
           as a substitute for coffee

Ambition - a poor excuse for not having
                enough sense to be lazy
---------------------------------------------------

Chas Douglass - 12 Dec 2004 17:01 GMT
"Konrad Den Ende" <tmp1@viltersten.com> wrote in news:cphjog$6g7$1
@news.gu.se:

> I'm trying to set labels on a JSlider and of what i see
> i have to make an instance of Dictionary class. Since
[quoted text clipped - 3 lines]
> Should i extend Dictionary class anyway or is there a
> better way to put my own labels on the ticks?

This looks like an oversight in the definition of JSlider.  Dictionary
has been replaced by the Map interface.

Still, you just need to supply the data in a form that meets the
Dictionary contract.

If you look at Dictionary in the javadocs you'll see that the only
"direct known subclass" is Hashtable.

Thus, you want to supply a set of values in a Hashtable (which by
definition meets the contract for a Dictionary).

The online tutorial gives this example:

//Create the slider
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 );

framesPerSecond.setPaintLabels(true);

Chas Douglass
Konrad Den Ende - 12 Dec 2004 18:04 GMT
>> Should i extend Dictionary class anyway or is there a
>> better way to put my own labels on the ticks?
[quoted text clipped - 4 lines]
> Thus, you want to supply a set of values in a Hashtable (which by
> definition meets the contract for a Dictionary).

Aha! I knew i missed something. Thanks for the help

Signature

Kindly
Konrad
---------------------------------------------------
May all spammers die an agonizing death; have no burial places;
their souls be chased by demons in Gehenna from one room to
another for all eternity and more.

Sleep - thing used by ineffective people
           as a substitute for coffee

Ambition - a poor excuse for not having
                enough sense to be lazy
---------------------------------------------------



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.