• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSlider value

 
Candy Bortniker
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Candy Bortniker
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try
if (source.getValueIsAdjusting())
{
int fps = (int) source.getValue();
}
 
Candy Bortniker
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That worked perfectly, thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic