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.
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.
Joined: Dec 18, 2003
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
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.