Overriding slider methods


So I have been modifying the lookandfeel of a slider and have changed LinearBarVertical to suite my needs, I added a thumbnail control (an ellipse) to drag the slider. The problem is unlike LinearVertical, LinearBarVertical will cut off the button and/or top of the thumbnail if the slider is dragged all the way, the border cuts it off. I have fixed this by modifying the isBar() method to not include LinearBarVertical in the Slider GUI class (Slider::Pimpl), however I cannot override the class from my application since it is private. Is there any way to do this without manually changing the method within the Slider GUI class?

Any help would be appreciated.


If you’re implementing your own L&F then you should just override the drawLinearSlider() method and draw whatever you want in there. You definitely shouldn’t need to change the internals of the Slider class to do this as it just calls this method in its paint() for linear sliders.

Hi Ed,

I tried that. but no matter what I do it treats the borders differently if one is LinearVertical and one is LinearBarVertical. I got rid of everything inside drawLinearSlider and made it so it does the exact same thing for LinearBarVertical and LinearVertical, however the border behavior remains for LinearBarVertical in that it cuts off the ellipse (thumb used for dragging) in LinearBarVertical but not in LinearVertical regardless of what I have for drawLinearSlider(). The only way I have managed to fix this is to take out LinearBarVertical form isBar(). I have no idea where this behavior is coded in, but I have tried everything with drawLinearSlider()


To clarify - here is an image of the two different sliders at their topmost position. If i get rid of LinearBarVertical being returned in isBar() in the slider GUI class the behavior becomes the same and the ellipse doesn’t cut off.

that is, because LinearVertical and LinearBarVertical are intended for a different purpose:
While the LinearVertical slider draws a thumb for manipulation, the LinearBarVertical is a display widget. That is why the default implementation doesn’t leave the padding space to contain a handle.

I hope this makes sense for your case…

Hi Daniel,

That makes sense. What would the recommended solution be then? I need two different sliders, one that acts like a LinearBarVertical slider, the same behavior and look but with an added thumb.

Is it a bad idea to change the slider GUI class for this one instance for a certain project?

Thanks for the help :slight_smile:

In that case I would suggest to create two separate LookAndFeel classes, that you can set for the individual sliders. If you inherit one of the implemented LookAndFeel_Vx you only need to override the specific methods.

I did the same, when I had one slider showing a polar pattern, another an angle and the third a standard value knob all next to each other.

Thank You!