• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSlider Float Values

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I started looking at the source code for the JSlider to see if I could write my own because I need to adjust float values, not integers. Things were going find until I relized I was going to need to update the model. There are commands throughout the JSlider class where getModel() is called. This model accepts integers as values, so I would need to possibly adjust the model as well, but can't seem to find the source for this model that JSlider is using. Any tips would be helpful.
Thanks.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
javax.swing.DefaultBoundedRangeModel?
but it uses integers...
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by maggie woo:
javax.swing.DefaultBoundedRangeModel?
but it uses integers...


I found that, and I even created my own class with the same name, and changed it all from ints to floats, but can't figure out how to tell my slider to get that model and not the BoundedRangeModel that it is getting.
I guess I am stuck right now with just casting from int to float as I get the value. But it sucks because in order to adjust the slider fractions I have to do some ugly division or multiplication.
 
maggie woo
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmm... seems like there's both a constructor to accept it as well as a setter. but you've probably already tried those too...
yes, you seem to have a sticky problem. closest i've ever used is the progress bar. seems like you may have to build your own if you want very fine control.
what precision are you looking at? forgive my lack of vocabulary here, but just for instance, can you use the original values x 1000 for the ints, and convert to floats in a dirty fashion for the input?
slider from -1.0 to 1.0 in .001 increments; pass in values -1000 to 1000, but display -1.0 to 1.0.
*shrug* i guess i shouldn't spend much time on this. it has nothing to do with anything i need or really know.
good luck.
maggie
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Spend as much time on it as you want maggie.
I the most precision I need is 0.1. So I could do what you suggested. It is dirty, but it should work. It's just the least amount of work I have to do with the values after the slider hands them to me the better. But I don't need it THAT bad I guess.
I am trying to learn opengl so I am creating a pretty basic modeling program and when I do rotation and translation and what not, I need to do that in float amounts.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic