Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Movie-like timeline with JSlider  RSS feed

 
John Sutt
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

The code below is an example of how I want to include a movie-like timeline component in my application.
I thought the easiest would be to make use of a JSlider. But somehow, I need to adjust the maximum/minimum
of the JSlider when the user is dragging the handle. I tried to simplify this a little bit, by only changing the
minimum/maximum when the user drags the knob to the min or max.

However, the way I make use of the ChangeListener now results in a StackOverflow. The single System.out.prinln
statement I've included shows that the current value grows along with the maximum value, even though I've tried
to reset it after the maximum is increased.

Does somebody know how to fix this?
Thanks!

 
Rob Spoor
Sheriff
Posts: 21090
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The changing of the minimum and maximum fire a stateChanged event as well. Therefore, in your event listener you should keep track of whether or not you're already handling an event. I usually do this using a boolean:
However, I don't really get why you need to change your minimum and maximum. In videos on Youtube etc, the minimum and maximum of a movie usually stay the same - the minimum at 00:00 and the maximum at the movie's end.
 
John Sutt
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perfect! That works fine.

I understand your remark about Youtube and others, but in my case, I want it like this because I want the
user to be able to position the movie at a fraction of a second, which is not normally required.
So if a movie takes longer than 5 minutes, I would have lost some precision. Now maybe I can get the
minimum/maximum to change even while dragging the knob. And if I can tune that nicely, this will
be exactly what I want.

Thank you.
 
Rob Spoor
Sheriff
Posts: 21090
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!