This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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 REST with Spring (video course) this week in the Spring 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: 15302

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.
I agree. Here's the link:
subject: JSlider value
It's not a secret anymore!