File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JSlider value" Watch "JSlider value" New topic
Author

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
    
    6

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
try
if (source.getValueIsAdjusting())
{
int fps = (int) source.getValue();
}
Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
That worked perfectly, thank you.
 
Consider Paul's rocket mass heater.
 
subject: JSlider value