Two Laptop Bag
The moose likes Swing / AWT / SWT and the fly likes grey bar in jslider Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "grey bar in jslider " Watch "grey bar in jslider " New topic

grey bar in jslider

olze oli
Ranch Hand

Joined: Jun 20, 2009
Posts: 149

following problem: i have an audio player which retrieves streams (mp3). the playback works fine, and the knob in the jslider moves as expected when the song plays.
but i want the user to be able to play forward and i want to display the user how much of the track has already been stored into ram.
any idea how i can achieve that? is there something already implemented in JSlider and i just didnt see it?

thanks in advance
Darryl Burke

Joined: May 03, 2008
Posts: 5115

If I correctly understand what you mean by "play forward" then no.

It's not just the display of JSlider, its model (BoundedRangeModel) only caters to one 'value'. Visually representing both the present play position as well as the stream load status would require two values.

some sort of implementation could probably be achieved with a custom UI delegate that uses the BoundedRangeModel's extent to "fill" the track between the slider thumb I(the "play" position) and the "load" position but this would by its nature be LaF dependent. You could try extending BasicSliderUI (or MetalSliderUI, or ...) and overriding paintTrack(...) starting with a call to the super implementation, and adding code to paint the track between the slider thumb and (maximum - extent). Your user code would have to setExtent(...) of the JSlider accordingly.

This would have a probably positive spinoff in that it is not possible to drag a slider thumb beyond (maximum - extent) so would thus prevent the user from foraying into a region of the stream that hasn't yet been received.

luck, db
There are no new questions, but there may be new answers.
olze oli
Ranch Hand

Joined: Jun 20, 2009
Posts: 149
yes you understood me.
Your answer sounds pretty hard to me - i'm not that java god like programmer ;)
I will take a look at BasicSliderUI

i am now able to draw a line... need further investigation how i can set the x y coordinates accordingly to the JSlider line and how to draw a "nice" line, not that strange thin thing, but this topic can be closed as it solved my problem, thanks ;)
I agree. Here's the link:
subject: grey bar in jslider
It's not a secret anymore!