jQuery in Action, 2nd edition*
The moose likes Swing / AWT / SWT and the fly likes JSlider value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JSlider value" Watch "JSlider value" New topic

JSlider value

Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
I have a JSlider that goes from 1-100. How can I make it go from 0 to 255?
Here is the code I have:
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299

During your journey through the Java language, your best friend will become the API. This is one of those questions that is really easy to answer, but also where the API could have saved you a little bit of time waiting here for an answer. If you look at the link above, you will notice that JSlider can take a min int and a max int in its constructor. You can also use the setMinimum(int) and setMaximum(int) methods to do the same thing. Of course, that adds 2 lines of code to your program. I am usually all about as little code as possible.

GenRocket - Experts at Building Test Data
Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
Thank you, the API was very helpful. I checked out the how to build a slider demo and copied so code that could be useful but it isn't working. I'm getting a compile error on fps. Any suggestions?
VIJAY Yadlapati
Ranch Hand

Joined: Aug 04, 2003
Posts: 175
if (source.getValueIsAdjusting())
int fps = (int) source.getValue();
Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
That worked perfectly, thank you.
It is sorta covered in the JavaRanch Style Guide.
subject: JSlider value
Similar Threads
slider problem
To make JLabel get the value from JSlider
problem drawOval() cant be found.
Jslider - Button
Extending a class; Must I explicitely call the super constructor?